G
GEL
Hi, I want to open a new browser window, let the user use that window
for several minutes, and when they close, I'd like to change the page
displayed in the original window.
According to numerous articles found Googling, this should work, but on
my WinXP system, using Firefox and IE, I get nothing (when allowing
pop-ups, if pop-ups are disabled, IE reports the window is closed,
Firefox gives a JS error on checking the window handle). No JS errors,
no notifications, nothing. Any pointers would be appreciated.
File 1 contains the code I'm using to open the window, to check for
closure, and a form textarea that I update with the time (mostly so I
know my timer is firing properly).
---- FILE 1 BEG ----
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Opener Page</title>
</head>
<body>
<h1>Opener</h1>
<form name="frmOutput">
<textarea name="txtOutput" rows=5 cols=80></textarea>
</form>
<p><a href="javascriptstopChecking();">Stop Checking</A></p>
<script language="Javascript">
log("Start", true);
var remoteWin = window.open("Remote.html", "remote", 'toolbar=no,
location=no, directories=no, status=yes, menubar=no, width=795,
height=500, resizable=yes, scrollbars=yes, screenx=0, screeny=0, top=0,
left=0');
var timer = null;
function checkClosed()
{
log("Checking...", false);
timer = setTimeout("checkClosed()", 5000); // Check every 5 seconds.
if (!remoteWin)
{
alert("Window no longer exists");
stopChecking();
}
else if (remoteWin.Closed)
{
alert("Window Closed");
stopChecking();
}
}
timer = setTimeout("checkClosed()", 5000); // Check every 5 seconds.
function stopChecking()
{
log("Stop checking.", false);
clearTimeout(timer);
}
function log(sText, bClearContents)
{
var d = new Date();
var s = d.getFullYear() + "." + d.getMonth() + "." + d.getDate() + " "
+ d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + " " +
sText + "\r\n";
if (bClearContents)
{
document.frmOutput.txtOutput.value = s;
}
else
{
document.frmOutput.txtOutput.value = s +
document.frmOutput.txtOutput.value;
}
}
</script>
</body>
</html>
---- FILE 1 END ----
File 2 contains some filler text. I can not change the source of this
window (when live).
---- FILE 2 BEG (remote.html) ----
<html><head><title>Remote</title></head><body><h1>Remote
Window</h1><p>Closing me should alert the original window or allow the
original window to know when I <a
href="javascriptwindow.close();">close</a>.</p></body></html>
---- FILE 2 END (remote.html) ----
TIA.
for several minutes, and when they close, I'd like to change the page
displayed in the original window.
According to numerous articles found Googling, this should work, but on
my WinXP system, using Firefox and IE, I get nothing (when allowing
pop-ups, if pop-ups are disabled, IE reports the window is closed,
Firefox gives a JS error on checking the window handle). No JS errors,
no notifications, nothing. Any pointers would be appreciated.
File 1 contains the code I'm using to open the window, to check for
closure, and a form textarea that I update with the time (mostly so I
know my timer is firing properly).
---- FILE 1 BEG ----
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Opener Page</title>
</head>
<body>
<h1>Opener</h1>
<form name="frmOutput">
<textarea name="txtOutput" rows=5 cols=80></textarea>
</form>
<p><a href="javascriptstopChecking();">Stop Checking</A></p>
<script language="Javascript">
log("Start", true);
var remoteWin = window.open("Remote.html", "remote", 'toolbar=no,
location=no, directories=no, status=yes, menubar=no, width=795,
height=500, resizable=yes, scrollbars=yes, screenx=0, screeny=0, top=0,
left=0');
var timer = null;
function checkClosed()
{
log("Checking...", false);
timer = setTimeout("checkClosed()", 5000); // Check every 5 seconds.
if (!remoteWin)
{
alert("Window no longer exists");
stopChecking();
}
else if (remoteWin.Closed)
{
alert("Window Closed");
stopChecking();
}
}
timer = setTimeout("checkClosed()", 5000); // Check every 5 seconds.
function stopChecking()
{
log("Stop checking.", false);
clearTimeout(timer);
}
function log(sText, bClearContents)
{
var d = new Date();
var s = d.getFullYear() + "." + d.getMonth() + "." + d.getDate() + " "
+ d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + " " +
sText + "\r\n";
if (bClearContents)
{
document.frmOutput.txtOutput.value = s;
}
else
{
document.frmOutput.txtOutput.value = s +
document.frmOutput.txtOutput.value;
}
}
</script>
</body>
</html>
---- FILE 1 END ----
File 2 contains some filler text. I can not change the source of this
window (when live).
---- FILE 2 BEG (remote.html) ----
<html><head><title>Remote</title></head><body><h1>Remote
Window</h1><p>Closing me should alert the original window or allow the
original window to know when I <a
href="javascriptwindow.close();">close</a>.</p></body></html>
---- FILE 2 END (remote.html) ----
TIA.