Skip to content

Instantly share code, notes, and snippets.

@roine
Last active December 26, 2015 07:09
Show Gist options
  • Select an option

  • Save roine/7112682 to your computer and use it in GitHub Desktop.

Select an option

Save roine/7112682 to your computer and use it in GitHub Desktop.
warn the user before to unload the page (closing) and if user agree to stay redirect him
var warn = true;
window.onbeforeunload = function(e){
e = e || window.event;
if(warn){
e.returnMessage = 'yop';
setTimeout(function(){
warn = false;
location.href='http://google.fr';
}, 1);
return 'Are you sure? I got a secret to show you before!';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment