Skip to main content

Bug Tracker

Side navigation

#8755 closed bug (fixed)

Opened April 02, 2011 08:41PM UTC

Closed April 17, 2011 05:22PM UTC

Last modified March 09, 2012 01:22PM UTC

binding to beforeunload throws an error in IE6, 7, 8 on page unload

Reported by: info@corrupt-system.de 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

1. Simply bind to the beforeunload event:

$(window).bind('beforeunload', $.noop);

2. 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)

Attachments (0)
Change History (13)

Changed April 02, 2011 08:46PM UTC by rwaldron comment:1

component: unfiledevent
resolution: → wontfix
status: newclosed

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.)"

Changed April 02, 2011 11:00PM UTC by anonymous comment:2

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?

Changed April 03, 2011 08:22AM UTC by info@corrupt-system.de comment:3

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

Changed April 03, 2011 03:44PM UTC by ajpiano comment:4

resolution: wontfix
status: closedreopened

Changed April 03, 2011 03:49PM UTC by ajpiano comment:5

keywords: → needsdocs
milestone: 1.next1.5.3
priority: undecidedblocker
status: reopenedopen

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.

Changed April 03, 2011 03:55PM UTC by ajpiano comment:6

#8737 is a duplicate of this ticket.

Changed April 03, 2011 08:13PM UTC by rwaldron comment:7

To explain your specific question above - I made a mistake, that's all :D

Changed April 08, 2011 01:55PM UTC by addyosmani comment:8

#8825 is a duplicate of this ticket.

Changed April 14, 2011 12:27AM UTC by speednet comment:9

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/)

Changed April 17, 2011 05:21PM UTC by john comment:10

milestone: 1.5.31.6

Changed April 17, 2011 05:21PM UTC by john comment:11

owner: → john
status: openassigned

Changed April 17, 2011 05:22PM UTC by John Resig comment:12

resolution: → fixed
status: assignedclosed

Make sure that there isn't an error if no event object exists. Fixes #8755.

Changeset: adef5c3550141960089e2634619ef028931f4765

Changed June 30, 2011 05:27AM UTC by addyosmani comment:13

keywords: needsdocsneededdocs

Updates to the docs related to this ticket have been made. Please see bind().