René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback -
 

The closed property of window [JavaScript]

<html>
  <head>
    <title>Detecting closed window</title>
  </head>

  <script language='javascript'>
    var w;
   
    function on_load() {
      w=window.open('about:blank', '', 'toolbar=no,scrollbars=yes,width=200,height=200,top=300,left=300');

      w.document.writeln('<html><body><h1>close me</h1></body></html>')
      w.document.close();
        setTimeout('check_if_closed()', 1000);
    }

    function check_if_closed() {
      if (w.closed) {
        alert('window had been closed');
      }
      else {
        setTimeout('check_if_closed()', 1000);
      }
    }
  </script>

  <body onLoad='on_load()'>
    <form>
      <input type='button' value='close'>
    </form>
  </body>
</html>