code_junkie

Javascript To Get An Alert To Redirect When Closing The Browser Window

Nov 13th, 2011
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. window.onbeforeunload = fget;
  2. function yPop(url) {
  3. var found = 1;
  4. window.onbeforeunload = '';
  5. window.location = url;
  6. return false;
  7. }
  8. function fget() {
  9. alert("Thank you for visiting our website, you are welcome any time! nn");
  10. window.location = "http://NewLink.com";
  11. return "n________________________nn PRESS 'CANCEL' To Stay On The Current Page nn________________________n";
  12. }
  13.  
  14. $(window).unload( function () { alert("Bye now!"); } );
  15.  
  16. <html>
  17. <head>
  18. <script type="text/javascript">
  19. var hook = true;
  20. window.onbeforeunload = function() {
  21. if (hook) {
  22. return "Did you save your stuff?"
  23. }
  24. }
  25. function unhook() {
  26. hook=false;
  27. }
  28. </script>
  29. </head>
  30. <body>
  31. <!-- this will ask for confirmation: -->
  32. <a href="http://google.com">external link</a>
  33.  
  34. <!-- this will go without asking: -->
  35. <a href="test.html" onClick="unhook()">internal link, un-hooked</a>
  36.  
  37. </body>
  38. </html>
Add Comment
Please, Sign In to add comment