From 06adf7c95d93507908181995a9ea15fe2729595a Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Mon, 3 Mar 2014 22:43:51 -0500 Subject: [PATCH] Event: Allow triggerHandler(beforeunload) Fixes #14791 --- src/event.js | 2 +- test/data/event/triggerunload.html | 18 ++++++++++++++++++ test/unit/event.js | 5 +++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 test/data/event/triggerunload.html diff --git a/src/event.js b/src/event.js index 8d4031211..ee1f3fcad 100644 --- a/src/event.js +++ b/src/event.js @@ -583,7 +583,7 @@ jQuery.event = { // Support: Firefox 20+ // Firefox doesn't alert if the returnValue field is not set. - if ( event.result !== undefined ) { + if ( event.result !== undefined && event.originalEvent ) { event.originalEvent.returnValue = event.result; } } diff --git a/test/data/event/triggerunload.html b/test/data/event/triggerunload.html new file mode 100644 index 000000000..a7879c772 --- /dev/null +++ b/test/data/event/triggerunload.html @@ -0,0 +1,18 @@ + + + + + diff --git a/test/unit/event.js b/test/unit/event.js index 22f6dacef..84cad50ac 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -2434,6 +2434,11 @@ testIframeWithCallback( "Focusing iframe element", "event/focusElem.html", funct ok( isOk, "Focused an element in an iframe" ); }); +testIframeWithCallback( "triggerHandler(onbeforeunload)", "event/triggerunload.html", function( isOk ) { + expect( 1 ); + ok( isOk, "Triggered onbeforeunload without an error" ); +}); + // need PHP here to make the incepted IFRAME hang if ( hasPHP ) { testIframeWithCallback( "jQuery.ready synchronous load with long loading subresources", "event/syncReady.html", function( isOk ) {