jQuery HTML Element How to - Handle window Unload event








Question

We would like to know how to handle window Unload event.

Answer


<!-- w w w . ja v a 2  s.  c  o  m-->
<html>
  <head>
    <script type="text/javascript" src='http://code.jquery.com/jquery-1.5.2.js'></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $(window).unload( function () { console.log("Bye now!"); } );
        });
    </script>
  </head>
  <body>
  </body>
</html>

The code above is rendered as follows: