handle window.onbeforeunload event - Javascript DOM Event

Javascript examples for DOM Event:onbeforeunload

Description

handle window.onbeforeunload event

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <div id="x"></div> 
      <script type="text/javascript">
var x = false;/*from  w w  w . jav a 2s  . c  o  m*/
document.getElementById('x').innerHTML = x;
window.onbeforeunload = function(e) {
    x = true;
    document.getElementById('x').innerHTML = x;
    return "unload";
}

      </script>  
   </body>
</html>

Related Tutorials