Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Javascript, Remote Window Close, Firefox and IE

Javascript, Remote Window Close, Firefox and IE

Scheduled Pinned Locked Moved Web Development
javascripthtmltoolshelpannouncement
5 Posts 3 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Glenn E Lanier II
    wrote on last edited by
    #1

    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) ---- <

    J M 2 Replies Last reply
    0
    • G Glenn E Lanier II

      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) ---- <

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      Dont know too much about FF, but very easy to get working for you in IE: Main file Opener Page

      Opener

      Stop Checking

      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();)

      G 1 Reply Last reply
      0
      • J J4amieC

        Dont know too much about FF, but very easy to get working for you in IE: Main file Opener Page

        Opener

        Stop Checking

        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();)

        G Offline
        G Offline
        Glenn E Lanier II
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • G Glenn E Lanier II

          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) ---- <

          M Offline
          M Offline
          Mattias Olgerfelt
          wrote on last edited by
          #4

          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

          G 1 Reply Last reply
          0
          • M Mattias Olgerfelt

            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

            G Offline
            G Offline
            Glenn E Lanier II
            wrote on last edited by
            #5

            It 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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups