Bug Tracker

Modify

Ticket #8755 (closed bug: fixed)

Opened 3 years ago

Last modified 2 years ago

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:
Blocking: Blocked by:

Description

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

comment:1 Changed 3 years ago by rwaldron

  • Status changed from new to closed
  • Resolution set to wontfix
  • Component changed from unfiled to event

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 3 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 3 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 3 years ago by ajpiano

  • Status changed from closed to reopened
  • Resolution wontfix deleted

comment:5 Changed 3 years ago by ajpiano

  • Keywords needsdocs added
  • Priority changed from undecided to blocker
  • Status changed from reopened to open
  • Milestone changed from 1.next to 1.5.3

 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 3 years ago by ajpiano

#8737 is a duplicate of this ticket.

comment:7 Changed 3 years ago by rwaldron

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

comment:8 Changed 3 years ago by addyosmani

#8825 is a duplicate of this ticket.

comment:9 Changed 3 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 3 years ago by john

  • Milestone changed from 1.5.3 to 1.6

comment:11 Changed 3 years ago by john

  • Owner set to john
  • Status changed from open to assigned

comment:12 Changed 3 years ago by John Resig

  • Status changed from assigned to closed
  • Resolution set to fixed

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

Changeset: adef5c3550141960089e2634619ef028931f4765

comment:13 Changed 3 years ago by addyosmani

  • Keywords neededdocs added; needsdocs removed

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

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.