#4106 closed bug (fixed)
binding to beforeunload does not work
Reported by: | dr_teeth | Owned by: | brandon |
---|---|---|---|
Priority: | major | Milestone: | 1.4 |
Component: | event | Version: | 1.4a1 |
Keywords: | beforeunload | Cc: | |
Blocked by: | Blocking: |
Description
A simple html page that binds to the beforeunload event does not work. The function gets called, but the alert box does not appear.
Test case below:
<head>
<title>Untitled Page</title> <script src="js/jquery-1.3.1.min.js" type="text/javascript"></script> <script type="text/javascript"> $(function() {
$(window).bind("beforeunload", function(e) {
e.returnValue="Test"; return "Test";
} );
});
</script>
</head> <body> Test page </body>
Change History (9)
comment:1 follow-up: 2 Changed 14 years ago by
Resolution: | → duplicate |
---|---|
Status: | new → closed |
comment:2 Changed 14 years ago by
comment:3 follow-up: 5 Changed 14 years ago by
Resolution: | duplicate |
---|---|
Status: | closed → reopened |
I think further discussion or work is warranted. I'd like to know why 'beforeunload' works perfectly in Adobe Spry but not jQuery? There's no specific 'beforeunload' code in Spry so perhaps there are issues with the way jQuery attaches the events?
// ACTION FUNCTION warnFormModified = function(e){ returnValue = "This form contains unsaved changes.\nYou will LOSE YOUR UPDATES if you press ok.\n\nTo save your work, press CANCEL below, then click\nthe UPDATE BUTTON in the page."; if (!e) { e = window.event; } else if (e) { e.returnValue = returnValue; } else { return returnValue; } }; // // ADOBE SPRY WORKS // Spry.Utils.addEventListener(window, "beforeunload", warnFormModified, true); // // JQUERY DOES NOT WORK // jQuery(window).bind("beforeunload", warnFormModified);
comment:4 Changed 14 years ago by
Milestone: | 1.3.2 → 1.3.3 |
---|
I'll take a look at this. I think we could utilize the special events api to work-around the cross-browser issues with this event.
comment:5 Changed 14 years ago by
Prototype also handles it correctly.
I tested a simple example that I was porting from Prototype. It works in Prototype but not jQuery. Searching Prototype's source, there's no specific mention of 'beforeunload', so I assume that it's treated like any other event, too - FWIW.
Replying to serious:
I think further discussion or work is warranted. I'd like to know why 'beforeunload' works perfectly in Adobe Spry but not jQuery? There's no specific 'beforeunload' code in Spry so perhaps there are issues with the way jQuery attaches the events?
// ACTION FUNCTION warnFormModified = function(e){ returnValue = "This form contains unsaved changes.\nYou will LOSE YOUR UPDATES if you press ok.\n\nTo save your work, press CANCEL below, then click\nthe UPDATE BUTTON in the page."; if (!e) { e = window.event; } else if (e) { e.returnValue = returnValue; } else { return returnValue; } }; // // ADOBE SPRY WORKS // Spry.Utils.addEventListener(window, "beforeunload", warnFormModified, true); // // JQUERY DOES NOT WORK // jQuery(window).bind("beforeunload", warnFormModified);
comment:7 Changed 14 years ago by
Any news on getting this fixed? Also can someone remove the spam post by 'jessica' above?
comment:9 Changed 13 years ago by
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Version: | 1.3.1 → 1.4a1 |
This was discussed in #1365 and closed as wontfix because the browsers don't treat this event normally. See the discussion there.