code_junkie

Can I override onbeforeunload for a particular element?

Nov 10th, 2011
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. <!-- clicking this link will do nothing. No onbeforeunload handler triggered.
  2. Nothing.
  3. And you could put something in before the return false bit...
  4. ...and the onunload handler would still not get called... -->
  5. <a href="http://www.google.com/" onclick="return false;">blah1</a>
  6. <!-- this should also do nothing, but IE will trigger the onbeforeunload
  7. handler -->
  8. <a href="javascript:void(0)">blah2</a>
  9.  
  10. Page.ClientScript.RegisterStartupScript(typeof(String), "ConfirmClose", @" <script> window.onbeforeunload = confirmExit; function confirmExit() { if(postback == false) return ""Please don't leave this page without clicking the 'Save Changes' or 'Discard Changes' buttons.""; } </script>");
  11.  
  12. OnClientClick="postback=true;return true;
  13.  
  14. <html>
  15. <head>
  16. <script language="Javascript" type="text/javascript">
  17. window.onbeforeunload = exitCheck;
  18. window.onunload = onCloseDoSomething;
  19.  
  20. function onCloseDoSomething()
  21. {
  22. alert("This is executed at unload");
  23. }
  24.  
  25. function exitCheck(evt)
  26. {
  27. return "Any string here."}
  28. </script>
  29. </head>
  30.  
  31. <frameset rows="100%">
  32. <FRAME name="main" src="http://www.yourDomain.com/yourActualPage.aspx">
  33. </frameset>
  34. <body>
  35. </body>
  36. </html>
Add Comment
Please, Sign In to add comment