Javascript, Remote Window Close, Firefox and IE
-
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="javascript:stopChecking();">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) ----<
-
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="javascript:stopChecking();">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) ----<
Dont know too much about FF, but very easy to get working for you in IE: Main file Opener Page
Opener
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'); function notifyClosed() { log("Window closed",false); } 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; } } remote window Remote function closeWithNotify() { window.opener.notifyClosed(); self.close(); }
Remote Window
Closing me should alert the original window or allow the original window to know when I [close](javascript:closeWithNotify();)
-
Dont know too much about FF, but very easy to get working for you in IE: Main file Opener Page
Opener
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'); function notifyClosed() { log("Window closed",false); } 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; } } remote window Remote function closeWithNotify() { window.opener.notifyClosed(); self.close(); }
Remote Window
Closing me should alert the original window or allow the original window to know when I [close](javascript:closeWithNotify();)
Thanks, but this requires modifying the remote page, which is not an option. I have no control over the pages being displayed in the remote window. --G
-
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="javascript:stopChecking();">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) ----<
Hi, this will work in IE... It is not a public standard so I don´t know how it works with FF.
var gRemoteWin function openWindow() { gRemoteWin = window.open("Test2.aspx", "remote"); timer = setTimeout("checkClosed()", 5000); } function checkClosed() { if (!gRemoteWin.closed) { alert('exists...' + gRemoteWin); timer = setTimeout("checkClosed()", 5000); } else { alert('does not exist ...'); } }
/M -
Hi, this will work in IE... It is not a public standard so I don´t know how it works with FF.
var gRemoteWin function openWindow() { gRemoteWin = window.open("Test2.aspx", "remote"); timer = setTimeout("checkClosed()", 5000); } function checkClosed() { if (!gRemoteWin.closed) { alert('exists...' + gRemoteWin); timer = setTimeout("checkClosed()", 5000); } else { alert('does not exist ...'); } }
/MIt works fine with FireFox. My code would have worked also, if I used remoteWin.closed instead of remoteWin.Closed. Thanks for pointing that out. --G