Created
January 31, 2012 00:17
-
-
Save camt/1707742 to your computer and use it in GitHub Desktop.
Prevent window close with JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkClose() { | |
if (ok) { | |
return "Have you saved your information?"; | |
} | |
} | |
var ok = true; // this is reset everytime a new page is loaded | |
function okToLeave() { // called if leaving the page is needed | |
ok = false; | |
} | |
window.onbeforeunload = checkClose; | |
window.onunload = checkClose; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment