Connecting Tech Pros Worldwide Help | Site Map

Prevent reload (redux)

  #1  
Old December 4th, 2005, 06:55 PM
skydanb
Guest
 
Posts: n/a
I'm a j-script (and html) newbie with what I thought was a simple
requirement:

1) From a link in a primary window open a secondary window
2) Want to specify size of secondary window
3) Want primary window NOT to reload when secondary opens

Don't want to prejudge the approach; I'm guessing Javascript can help,
and in fact have accomplished 1) and 2) above with the following,
embedded in the body of the primary window html:

<a href="javascript:location='primary_window.html';
window.open('secondary_window.html', 'secondary_window_label',
'height=345,width=550')">link_text</a>

But when the secondary window opens, the primary window reloads. I've
seen earlier posts addressing this problem (or similar ones), but I
haven't been able to make any of the suggestions work. Any guidance
much appreciated.

  #2  
Old December 4th, 2005, 07:15 PM
Randy Webb
Guest
 
Posts: n/a

re: Prevent reload (redux)


skydanb said the following on 12/4/2005 1:46 PM:[color=blue]
> I'm a j-script (and html) newbie with what I thought was a simple
> requirement:
>
> 1) From a link in a primary window open a secondary window
> 2) Want to specify size of secondary window
> 3) Want primary window NOT to reload when secondary opens
>
> Don't want to prejudge the approach; I'm guessing Javascript can help,
> and in fact have accomplished 1) and 2) above with the following,
> embedded in the body of the primary window html:
>
> <a href="javascript:location='primary_window.html';
> window.open('secondary_window.html', 'secondary_window_label',
> 'height=345,width=550')">link_text</a>
>
> But when the secondary window opens, the primary window reloads.[/color]

Thats because you are telling it to in the href attribute.
And don't use javascript: hrefs. It's in the FAQ.
[color=blue]
> I've seen earlier posts addressing this problem (or similar ones), but I
> haven't been able to make any of the suggestions work. Any guidance
> much appreciated.[/color]

And you didn't find this solution?

<a href="secondary_window.html" target="secondary_window_label"
onclick="window.open(this.href,this.target,'attrib utes here')">
link_text</a>


--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
  #3  
Old December 4th, 2005, 10:45 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a

re: Prevent reload (redux)


skydanb wrote:
[color=blue]
> 1) From a link in a primary window open a secondary window
> 2) Want to specify size of secondary window
> 3) Want primary window NOT to reload when secondary opens
>
> Don't want to prejudge the approach; I'm guessing Javascript can help,
> and in fact have accomplished 1) and 2) above with the following,
> embedded in the body of the primary window html:
>
> <a href="javascript:location='primary_window.html';
> window.open('secondary_window.html', 'secondary_window_label',
> 'height=345,width=550')">link_text</a>[/color]

This is utter nonsense, indeed.
[color=blue]
> But when the secondary window opens, the primary window reloads.[/color]

By chance: because the assignment to `location' comes first, it is
conceivable and reasonable that the second statement will not even
be executed.

But why, you are "reloading the primary window" yourself by assigning
a value to the `location' property. Stop that and use proper event
handlers, and nothing reloads.
[color=blue]
> I've seen earlier posts addressing this problem (or similar ones),
> but I haven't been able to make any of the suggestions work. Any
> guidance much appreciated.[/color]

....
<head>
...
<meta http-equiv="Content-Script-Type" content="text/javascript">
...
<script type="text/javascript">
function myOpen()
{
return! window.open(
'secondary_window.html',
'secondarywindowlabel',
'height=345,width=550'); // what about 640x480 or smaller?
}

// ...
</script>
...
</head>
<body>
...
<a href="primary_window.html" onclick="return myOpen();">link_text</a>
...
</body>
....

Still it remains unclear what you are trying to achieve _exactly_.


PointedEars
  #4  
Old December 7th, 2005, 10:45 PM
skydanb
Guest
 
Posts: n/a

re: Prevent reload (redux)


Since you ask what I'm trying to achieve, I'll risk boring you by
telling you, but first...

Your code worked!!! You're a genius, PointedEars! Thanks for the
helping hand.

Back to your question: I'm writing an html "book"--basically just a
long doc of scrollable text--on Bach. The text contains discussions of
many notated musical examples. I launch these examples in a smallish
secondary window. When I do this, I don't want the underlying "book"
text to reload--which would take the reader back to the beginning of
the text, rather than holding his reading-place in it. Hence the
importance for my purposes of kind of code you've kindly supplied.
Having given some context, maybe I'll push my luck with a follow-up
question. I'd like force the secondary window with the musical example
to stay visible ("on top"?), even if the reader returns focus to the
underlying text (which he may do to scroll around in the text while
continuing to look at the example to which it refers). I suspect
keeping a window visible in this way is more an HTML thing than an
javascript thing, but I thought maybe you'd know.... Thanks for any
help.

PS The notated musical examples are presented in a technology called
"Scorch" from a company called Sibelius. With this technology the
example can be played in audio, and as the music plays a kind of cursor
marches along with the notes: excellent aid for someone who can't read
music. (It also lets the listener slow the music down; again, useful
for the inexperienced listener who can follow events more easily if
they don't go by as quickly.) Scorch is enabled via a free plug-in
from Sibelius. If you're interested in things musical you might want
to check it out.

  #5  
Old December 7th, 2005, 10:55 PM
skydanb
Guest
 
Posts: n/a

re: Prevent reload (redux)


Thanks for the suggestions (and sorry for my ignorance; when I call
myself a newbie I'm understating the matter). I tried your solution,
and it helped (the primary window indeed did not reload), but somehow I
got TWO additional windows to pop up rather than just one (undoubtedly
because I messed up somehow). I played with ways of getting just one
additional window for a while without success, then tried the rather
different (I think) approach suggested by PointedEars in another
response to my post. That approach worked; got a single secondary
window to pop up without reloading the primary. Just wanted to thank
you for taking the time to respond. Another thing I'm a newbie at is
boards, and I'm very impressed with generosity and expertise to be
found on them.

  #6  
Old December 8th, 2005, 03:05 AM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a

re: Prevent reload (redux)


skydanb wrote:
[color=blue]
> Since you ask what I'm trying to achieve, I'll risk boring you by
> telling you, but first...[/color]

.... you wanted to quote the minimum of what you are replying to but
accidentally forgot it ;-)

Please take heed of <URL:http://jibbering.com/faq/faq_notes/pots1.html>.
[color=blue]
> Your code worked!!! You're a genius, PointedEars! Thanks for the
> helping hand.[/color]

Thank you, too. And you're welcome.

Reviewing my code, the typo

return! window.open(...);

works because of the language grammar (see ECMAScript 3, 12.9 and 11.4.9),
however better code style is

return !window.open(...);

leaving whitespace between keyword and statement parameter, and placing the
operator `!' next to its operand.
[color=blue]
> Back to your question: I'm writing an html "book"--basically just a
> long doc of scrollable text--on Bach.[/color]

Ahh, Bach :)
[color=blue]
> The text contains discussions of many notated musical examples. I launch
> these examples in a smallish secondary window. When I do this, I don't
> want the underlying "book" text to reload--which would take the reader
> back to the beginning of the text, rather than holding his reading-place
> in it. Hence the importance for my purposes of kind of code you've kindly
> supplied.[/color]

Note that the approach I presented excludes users without client-side
scripting or popup blocker unless you include a viable alternative for
`primary_window.html'.

You may also want to consider using DHTML layers (layer, div and other
block elements that are displayed on demand and hidden when no longer
needed) as additional alternative to popup windows where the latter take
much more system resources (which are not always completely freed when
the window is closed, if it even opened [see: popup blocker]). In compliant
user agents, a show-on-hover feature even can be realized with CSS only.
[color=blue]
> Having given some context, maybe I'll push my luck with a follow-up
> question. I'd like force the secondary window with the musical example
> to stay visible ("on top"?), even if the reader returns focus to the
> underlying text (which he may do to scroll around in the text while
> continuing to look at the example to which it refers).[/color]

It is not possible to do that with client-side scripting alone. Attempts at
forcing the window to stay on top are futile and provably harmful if they
succeeed (think about other application windows).

<URL:http://developer.mozilla.org/en/docs/DOM:window.open>

Note that "dependent" windows are described to stay on top on Windows
platforms; this feature is not supported on MacOS X and dependent[=yes]
does not work here in Firefox/1.0.7 running with KDE 3.4 on GNU/Linux.

However, if you used DHTML layers, there would not be that problem.
(There would be another ;-))
[color=blue]
> I suspect keeping a window visible in this way is more an HTML thing than
> an javascript thing,[/color]

No, HTML does not even "know" about windows. All that counts there
(and in CSS) is the client area, the viewport.
[color=blue]
> [Scorch] Scorch is enabled via a free plug-in from Sibelius. If
> you're interested in things musical you might want to check it out.[/color]

Will do, thanks.


PointedEars
Closed Thread