Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Event: Allow triggerHandler(beforeunload)
Fixes #14791
  • Loading branch information
dmethvin committed Mar 5, 2014
1 parent 3a68c11 commit 06adf7c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/event.js
Expand Up @@ -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;
}
}
Expand Down
18 changes: 18 additions & 0 deletions test/data/event/triggerunload.html
@@ -0,0 +1,18 @@
<!doctype html>
<html>
<script src="../../jquery.js"></script>
<script>
var called = false,
error = false;

window.onerror = function() { error = true; };

jQuery( window ).on( "beforeunload", function( event ) {
called = true;
return "maybe";
}).on( "load", function( event ) {
$( window ).triggerHandler( "beforeunload" );
window.parent.iframeCallback( called && !error );
});
</script>
</html>
5 changes: 5 additions & 0 deletions test/unit/event.js
Expand Up @@ -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 ) {
Expand Down

0 comments on commit 06adf7c

Please sign in to comment.