From: Oleg Date: Tue, 14 Aug 2012 20:10:10 +0000 (+0400) Subject: Fix #12061. Avoid window.onbeforeunload to permit multiple handlers. Close gh-894. X-Git-Tag: 1.9.0b1~159 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9dd0b010174dbfa70142a995a875a316337e1913;p=jquery.git Fix #12061. Avoid window.onbeforeunload to permit multiple handlers. Close gh-894. --- diff --git a/src/event.js b/src/event.js index 330310fc8..499a30397 100644 --- a/src/event.js +++ b/src/event.js @@ -549,16 +549,11 @@ jQuery.event = { }, beforeunload: { - setup: function( data, namespaces, eventHandle ) { - // We only want to do this special case on windows - if ( jQuery.isWindow( this ) ) { - this.onbeforeunload = eventHandle; - } - }, + postDispatch: function( event ) { - teardown: function( namespaces, eventHandle ) { - if ( this.onbeforeunload === eventHandle ) { - this.onbeforeunload = null; + // Even when returnValue equals to undefined Firefox will still show alert + if ( event.result !== undefined ) { + event.originalEvent.returnValue = event.result; } } } diff --git a/test/unit/event.js b/test/unit/event.js index 753691995..727e20ac2 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -1369,20 +1369,63 @@ test("Submit event can be stopped (#11049)", function() { form.remove(); }); -test("on(beforeunload) creates/deletes window property instead of adding/removing event listener", function() { - expect(3); +// Test beforeunload event only if it supported (i.e. not Opera) +if ( window.onbeforeunload === null ) { + asyncTest("on(beforeunload)", 4, function() { + var doc, + forIE6 = 0, + iframe = jQuery("