Can I focus a popup window without refreshing it?

J

Jamie Jackson

The crux of the problem is I only know if the popup *has been* opened,
but not if it *is* open. Therefore, the script doesn't know whether to
simply refocus, or whether to popup a fresh window.

Are these the only solutions?
* handle onerror in some creative way
* hidden frames

BTW, I do have the luxury of ignoring non IE 5.5+ browsers on this
project, if it helps.

Thanks,
Jamie
 
G

Grant Wagner

Jamie said:
The crux of the problem is I only know if the popup *has been* opened,
but not if it *is* open. Therefore, the script doesn't know whether to
simply refocus, or whether to popup a fresh window.

Are these the only solutions?
* handle onerror in some creative way
* hidden frames

BTW, I do have the luxury of ignoring non IE 5.5+ browsers on this
project, if it helps.

Thanks,
Jamie

Just attempt to window.open() with the same window name (2nd parameter).
If the window is open, the new URL will load in it, if it's not open, it
will open a new window with that name.

These will open in the same window:
<a href="#" onclick="window.open('http://www.yahoo.com',
'theWindow');return false;">Yahoo</a>
<a href="#" onclick="window.open('http://www.microsoft.com',
'theWindow');return false;">MS</a>
<a href="http://www.ebay.com" target="theWindow">eBay</a>

These will open in a different window:
<a href="http://www.cnn.com" target="_blank">CNN</a>
<a href="#" onclick="window.open('http://www.msnbc.com',
'someOtherWindow');return false;">msnbc</a>

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 
J

Jamie Jackson

Just attempt to window.open() with the same window name (2nd parameter).
If the window is open, the new URL will load in it, if it's not open, it
will open a new window with that name.

These will open in the same window:
<a href="#" onclick="window.open('http://www.yahoo.com',
'theWindow');return false;">Yahoo</a>
<a href="#" onclick="window.open('http://www.microsoft.com',
'theWindow');return false;">MS</a>
<a href="http://www.ebay.com" target="theWindow">eBay</a>

These will open in a different window:
<a href="http://www.cnn.com" target="_blank">CNN</a>
<a href="#" onclick="window.open('http://www.msnbc.com',
'someOtherWindow');return false;">msnbc</a>

Thanks for the reply. Unfortunately (unless I missed something), I
don't think the question (of how to keep the popup from refreshing)
has been addressed.

Here's why I'd prefer that it didn't refresh: I've got a good bit of
content (help files) in the popup, and I don't want to lose the scroll
position, since the user might be in the middle of reading something,
they click on the parent, and they want to go back to the popup (by
re-clicking the help link from the parent). It would be nice if I just
refocused that window the next time the "help" link was clicked,
instead of reloading the URL into that window, and starting from
scratch.

Any ideas?

Thanks,
Jamie
 
D

Dom Leonard

Jamie said:
how to keep the popup from refreshing

window.closed may provide the answer:


var hwin=null;

function showHelp(href)
{
if(hwin && !hwin.closed)
hwin.focus();
else
hwin=window.open(href,"help_win");
}

.....

<a href="help.html"
onclick="showHelp(this.href);return false;"
help </a>


The closed property was introduced in javascript 1.1, and although not
standardised is widely implemented. For further information on
downloading Netscape documentation for Javascript 1.3, please consult
the NG FAQ

Dom
========
http://www.jibbering.com/faq/#FAQ3_2
 
J

Jamie Jackson

Hmm, I'll play with that. Thanks!

Jamie

window.closed may provide the answer:


var hwin=null;

function showHelp(href)
{
if(hwin && !hwin.closed)
hwin.focus();
else
hwin=window.open(href,"help_win");
}

....

<a href="help.html"
onclick="showHelp(this.href);return false;"


The closed property was introduced in javascript 1.1, and although not
standardised is widely implemented. For further information on
downloading Netscape documentation for Javascript 1.3, please consult
the NG FAQ

Dom
========
http://www.jibbering.com/faq/#FAQ3_2
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top