Monitoring status of another browser window

M

Mike May

Hi

IE6 Win2k

The javascript FAQ describes how you can retain a reference to a window that
you have opened and manipulate the window - focus on it or close it, viz:

4.10 How do I check to see if a childwindow is open, before opening another?
var myWin=null;
function openWin(aURL) {
if (!myWin || myWin.closed ) {
myWin=window.open(aURL,'myWin');
} else{
myWin.location=aURL;
myWin.focus();
}
}

However, javascript variables appear to be reinitialised each time the
browser window
is refreshed so the mechanism described by the FAQ seems to be defeated if
the user refreshes the page.

a) Is it true that javascript variables are reinitiliised when the page is
refreshed?
b) If a) then is there some other way to monitor a child window from another
browser window despite user refreshes?

Thanks
Mike May
 
R

Randy Webb

Mike said:
Hi

IE6 Win2k

The javascript FAQ describes how you can retain a reference to a window that
you have opened and manipulate the window - focus on it or close it, viz:

4.10 How do I check to see if a childwindow is open, before opening another?
var myWin=null;
function openWin(aURL) {
if (!myWin || myWin.closed ) {
myWin=window.open(aURL,'myWin');
} else{
myWin.location=aURL;
myWin.focus();
}
}

However, javascript variables appear to be reinitialised each time the
browser window
is refreshed so the mechanism described by the FAQ seems to be defeated if
the user refreshes the page.

Yep :)
a) Is it true that javascript variables are reinitiliised when the page is
refreshed?

Tis indeed the truth. Easy to test to.

alert(b)
b = "ok, it has a value now"
alert(b)
and then refresh the page......
b) If a) then is there some other way to monitor a child window from another
browser window despite user refreshes?

Use a cookie or sessions.
 
L

Lasse Reichstein Nielsen

Mike May said:
Hi

IE6 Win2k

The javascript FAQ describes how you can retain a reference to a window that
you have opened and manipulate the window - focus on it or close it, viz:

4.10 How do I check to see if a childwindow is open, before opening another?
var myWin=null;
function openWin(aURL) {
if (!myWin || myWin.closed ) {
myWin=window.open(aURL,'myWin');
} else{
myWin.location=aURL;
myWin.focus();
}
}

However, javascript variables appear to be reinitialised each time the
browser window
is refreshed so the mechanism described by the FAQ seems to be defeated if
the user refreshes the page.

a) Is it true that javascript variables are reinitiliised when the page is
refreshed?

Yes. There is no differene between
b) If a) then is there some other way to monitor a child window from another
browser window despite user refreshes?

Only very trickily.

If you try to open a window again with the same name, and it already
exists, you will be given a new reference to the window. It will probably
also change the content of the window.

If you control the content of the opened window, you can have it keep
check of its parent and write its own reference back to it. That is hard
to time correctly though.

/L
 

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

Forum statistics

Threads
473,781
Messages
2,569,619
Members
45,316
Latest member
naturesElixirCBDGummies

Latest Threads

Top