By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,341 Members | 1,700 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,341 IT Pros & Developers. It's quick & easy.

Prevent reload (redux)

P: 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.

Dec 4 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
skydanb said the following on 12/4/2005 1:46 PM:
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.
Thats because you are telling it to in the href attribute.
And don't use javascript: hrefs. It's in the FAQ.
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.


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/
Dec 4 '05 #2

P: n/a
skydanb wrote:
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>
This is utter nonsense, indeed.
But when the secondary window opens, the primary window reloads.
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.
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.


....
<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
Dec 4 '05 #3

P: n/a
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.

Dec 7 '05 #4

P: n/a
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.

Dec 7 '05 #5

P: n/a
skydanb wrote:
Since you ask what I'm trying to achieve, I'll risk boring you by
telling you, but first...
.... 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>.
Your code worked!!! You're a genius, PointedEars! Thanks for the
helping hand.
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.
Back to your question: I'm writing an html "book"--basically just a
long doc of scrollable text--on Bach.
Ahh, 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.
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.
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).
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 ;-))
I suspect keeping a window visible in this way is more an HTML thing than
an javascript thing,
No, HTML does not even "know" about windows. All that counts there
(and in CSS) is the client area, the viewport.
[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.


Will do, thanks.
PointedEars
Dec 8 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.