Javascript examples for DOM Event:onbeforeunload
handle window.onbeforeunload event
<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>