var altKey = false; var keyCode = 0; function closeSession(evt){ evt = (evt) ? evt : event; clickY = evt.clientY; altKey = evt.altKey; keyCode = evt.keyCode; if(!evt.clientY){ // Window Closing in FireFox // capturing ALT + F4 keyVals = document.getElementById('ffKeyTrap'); if(keyVals.value == 'true115'){ return 'close 1'; } if(keyVals.value == ''){ // capturing a window close by "X" ? // we have no keycodes return 'close 2'; } } else { // Window Closing in IE // capturing ALT + F4 if (altKey == true && keyCode == 115){ alert('close 1'); // capturing a window close by "X" } else if(clickY < 0){ alert('close 2'); // simply leaving the page via a link } else { //alert('close 3'); return void(0); } } } function whatKey(evt){ evt = (evt) ? evt : event; keyVals = document.getElementById('ffKeyTrap'); altKey = evt.altKey; keyCode = evt.keyCode; if(altKey && keyCode == 115){ keyVals.value = String(altKey) + String(keyCode); } } window.onkeydown = whatKey; window.onbeforeunload = closeSession;
<html> <body> <script type="text/javascript"> window.onbeforeunload = check; function check() { return "Are you sure you want to exit this page?"; //or put whatever function you need to call when a user closes the web //browser. } </script> </body> </html>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)