Last active
December 26, 2015 07:09
-
-
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
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
| 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