JavaScript – Confirm Before Window is Closed

Here is the JavaScript code:
1
2
3
4
5
6
7
8
9
10
/** Confirms when closing the window **/
function checkClose()
{
    $("#s_scan_number").focus();
    return "Please DON'T close the window. Use the form button on the bottom.";
}
window.onbeforeunload = checkClose;
 
//to remove the confirmation dynamically:
window.onbeforeunload = null;

1 comment: