Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#8755 closed bug (fixed)

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

Reported by: info@… Owned by: john
Priority: blocker Milestone: 1.6
Component: event Version: 1.5.2
Keywords: neededdocs Cc:
Blocked by: Blocking:


Take IE8 and start debug in script panel

  1. Simply bind to the beforeunload event:
$(window).bind('beforeunload', $.noop);
  1. 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 ) :


Instead of:



(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 Rick Waldron

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

comment:2 Changed 12 years ago by anonymous

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 info@…

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 ajpiano

Resolution: wontfix
Status: closedreopened

comment:5 Changed 12 years ago by ajpiano

Keywords: needsdocs added
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.

comment:6 Changed 12 years ago by ajpiano

#8737 is a duplicate of this ticket.

comment:7 Changed 12 years ago by Rick Waldron

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

comment:8 Changed 12 years ago by addyosmani

#8825 is a duplicate of this ticket.

comment:9 Changed 12 years ago by speednet

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 john


comment:11 Changed 12 years ago by john

Owner: set to john
Status: openassigned

comment:12 Changed 12 years ago by John Resig

Resolution: fixed
Status: assignedclosed

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

Changeset: adef5c3550141960089e2634619ef028931f4765

comment:13 Changed 12 years ago by addyosmani

Keywords: neededdocs added; needsdocs removed

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

Note: See TracTickets for help on using tickets.