Skip to content

Instantly share code, notes, and snippets.

@camt
Created January 31, 2012 00:17
Show Gist options
  • Save camt/1707742 to your computer and use it in GitHub Desktop.
Save camt/1707742 to your computer and use it in GitHub Desktop.
Prevent window close with JS
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