#8755 closed bug (fixed)
binding to beforeunload throws an error in IE6, 7, 8 on page unload
Reported by: | Owned by: | john | |
---|---|---|---|
Priority: | blocker | Milestone: | 1.6 |
Component: | event | Version: | 1.5.2 |
Keywords: | neededdocs | Cc: | |
Blocked by: | Blocking: |
Description
Take IE8 and start debug in script panel
- Simply bind to the beforeunload event:
$(window).bind('beforeunload', $.noop);
- Reload/leave the page
-> result:
SCRIPT5007: Unable to get value of the property 'type': object is null or undefined jquery.js, line 2206 character 5
A possible fix could look like this:
if ( !eventHandle ) { elemData.handle = eventHandle = function( e ) { // Handle the second event of a trigger and when // an event is called after a page has unloaded return typeof jQuery !== "undefined" && jQuery.event.triggered !== (e || window.event || {type: 'undef'}).type ? jQuery.event.handle.apply( eventHandle.elem, arguments ) : undefined; }; }
Diff:
Instead of:
e.type
do:
(e || window.event || {type: 'undef'}).type
This bug was introduced with jQuery 1.5.2 (don't know, why it was changed, so fix could look different)
Change History (13)
comment:1 Changed 12 years ago by
Component: | unfiled → event |
---|---|
Resolution: | → wontfix |
Status: | new → closed |
comment:2 Changed 12 years ago by
I'm now a little bit confused. jQuery does have code to handle 'beforeunload' event special (see $.event.special.beforeunload). Can you explain, why there is code for something, that is not supported?
comment:3 Changed 12 years ago by
Hi again,
I have changed my code, but it would be nice, if you could answer the question from the previous post.
Only, because I'm confused and want to know the answer. Am I missing something?
regards alex
comment:4 Changed 12 years ago by
Resolution: | wontfix |
---|---|
Status: | closed → reopened |
comment:5 Changed 12 years ago by
Keywords: | needsdocs added |
---|---|
Milestone: | 1.next → 1.5.3 |
Priority: | undecided → blocker |
Status: | reopened → open |
http://jsfiddle.net/p9tAp/1/show/ - jQuery 1.5.1 - works fine in IE http://jsfiddle.net/p9tAp/2/show/ - jQuery GIT (post 1.5.2) - broken in IE at present
It's my understanding that jQuery added real support for handling the beforenload event, and it was working fine in 1.5.1, so this is a regression and it should be fixed. It would appear to me that the documentation on .bind is currently incorrect.
comment:7 Changed 12 years ago by
To explain your specific question above - I made a mistake, that's all :D
comment:9 Changed 12 years ago by
I can confirm this bug, and I hope it's fixed soon. I patched jQuery with the fix mentioned in the initial post, and it solves the problem.
This jQuery regression bug breaks the Watermark plugin, because the Watermark plugin uses the beforeunload event to remove watermarks before form submission. (http://jquery-watermark.googlecode.com/)
comment:10 Changed 12 years ago by
Milestone: | 1.5.3 → 1.6 |
---|
comment:11 Changed 12 years ago by
Owner: | set to john |
---|---|
Status: | open → assigned |
comment:12 Changed 12 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Make sure that there isn't an error if no event object exists. Fixes #8755.
Changeset: adef5c3550141960089e2634619ef028931f4765
comment:13 Changed 12 years ago by
Keywords: | neededdocs added; needsdocs removed |
---|
Updates to the docs related to this ticket have been made. Please see bind().
From: http://api.jquery.com/bind/
"The .bind() method is the primary means of attaching behavior to a document. All JavaScript event types, such as focus, mouseover, and resize, are allowed for eventType. (The beforeunload and error events on the window object use nonstandard conventions and are not supported by jQuery; attach a handler directly to the window object instead.)"