mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
Event: Allow triggerHandler(beforeunload)
Fixes #14791
(cherry picked from commit 06adf7c95d
)
Conflicts:
src/event.js
This commit is contained in:
parent
48837b92b0
commit
93fdfa2d8c
@ -616,8 +616,9 @@ jQuery.event = {
|
|||||||
beforeunload: {
|
beforeunload: {
|
||||||
postDispatch: function( event ) {
|
postDispatch: function( event ) {
|
||||||
|
|
||||||
// Even when returnValue equals to undefined Firefox will still show alert
|
// Support: Firefox 20+
|
||||||
if ( event.result !== undefined ) {
|
// Firefox doesn't alert if the returnValue field is not set.
|
||||||
|
if ( event.result !== undefined && event.originalEvent ) {
|
||||||
event.originalEvent.returnValue = event.result;
|
event.originalEvent.returnValue = event.result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
18
test/data/event/triggerunload.html
Normal file
18
test/data/event/triggerunload.html
Normal file
@ -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>
|
@ -2522,6 +2522,11 @@ testIframeWithCallback( "Focusing iframe element", "event/focusElem.html", funct
|
|||||||
ok( isOk, "Focused an element in an iframe" );
|
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
|
// need PHP here to make the incepted IFRAME hang
|
||||||
if ( hasPHP ) {
|
if ( hasPHP ) {
|
||||||
testIframeWithCallback( "jQuery.ready synchronous load with long loading subresources", "event/syncReady.html", function( isOk ) {
|
testIframeWithCallback( "jQuery.ready synchronous load with long loading subresources", "event/syncReady.html", function( isOk ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user