Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
9dd0b010
Commit
9dd0b010
authored
Aug 14, 2012
by
Oleg
Committed by
Dave Methvin
Oct 21, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #12061. Avoid window.onbeforeunload to permit multiple handlers. Close gh-894.
parent
08341437
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
18 deletions
+56
-18
event.js
src/event.js
+4
-9
event.js
test/unit/event.js
+52
-9
No files found.
src/event.js
View file @
9dd0b010
...
@@ -549,16 +549,11 @@ jQuery.event = {
...
@@ -549,16 +549,11 @@ jQuery.event = {
},
},
beforeunload
:
{
beforeunload
:
{
setup
:
function
(
data
,
namespaces
,
eventHandle
)
{
postDispatch
:
function
(
event
)
{
// We only want to do this special case on windows
if
(
jQuery
.
isWindow
(
this
)
)
{
this
.
onbeforeunload
=
eventHandle
;
}
},
teardown
:
function
(
namespaces
,
eventHandle
)
{
// Even when returnValue equals to undefined Firefox will still show alert
if
(
this
.
onbeforeunload
===
eventHandle
)
{
if
(
event
.
result
!==
undefined
)
{
this
.
onbeforeunload
=
null
;
event
.
originalEvent
.
returnValue
=
event
.
result
;
}
}
}
}
}
}
...
...
test/unit/event.js
View file @
9dd0b010
...
@@ -1369,20 +1369,63 @@ test("Submit event can be stopped (#11049)", function() {
...
@@ -1369,20 +1369,63 @@ test("Submit event can be stopped (#11049)", function() {
form
.
remove
();
form
.
remove
();
});
});
test
(
"on(beforeunload) creates/deletes window property instead of adding/removing event listener"
,
function
()
{
// Test beforeunload event only if it supported (i.e. not Opera)
expect
(
3
);
if
(
window
.
onbeforeunload
===
null
)
{
asyncTest
(
"on(beforeunload)"
,
4
,
function
()
{
var
doc
,
forIE6
=
0
,
iframe
=
jQuery
(
"<iframe src='data/iframe.html' />"
);
iframe
.
appendTo
(
"#qunit-fixture"
).
one
(
"load"
,
function
()
{
doc
=
iframe
[
0
].
contentWindow
||
iframe
[
0
].
contentDocument
;
jQuery
(
doc
).
on
(
"beforeunload"
,
function
()
{
ok
(
true
,
"beforeunload event is fired"
);
});
strictEqual
(
doc
.
onbeforeunload
,
null
,
"onbeforeunload property on window object still equals null"
);
jQuery
(
doc
).
on
(
"beforeunload"
,
function
()
{
// On iframe in IE6 beforeunload event will not fire if event is binded through window object,
// nevertheless, test should continue
window
.
setTimeout
(
function
()
{
if
(
!
forIE6
)
{
checker
();
}
});
});
doc
.
onbeforeunload
=
function
()
{
if
(
!
forIE6
)
{
forIE6
++
;
checker
();
}
};
equal
(
window
.
onbeforeunload
,
null
,
"window property is null/undefined up until now"
);
function
checker
()
{
ok
(
true
,
"window.onbeforeunload handler is called"
);
iframe
=
jQuery
(
"<iframe src='data/iframe.html' />"
);
var
handle
=
function
()
{};
iframe
.
appendTo
(
"#qunit-fixture"
).
one
(
"load"
,
function
()
{
jQuery
(
window
).
on
(
"beforeunload"
,
handle
)
;
doc
=
iframe
[
0
].
contentWindow
||
iframe
[
0
].
contentDocument
;
equal
(
typeof
window
.
onbeforeunload
,
"function"
,
"window property is set to a function"
);
jQuery
(
doc
).
on
(
"beforeunload"
,
function
()
{
strictEqual
(
doc
.
onbeforeunload
,
null
,
"Event handler is fired, even when onbeforeunload property on window is nulled"
);
jQuery
(
window
).
off
(
"beforeunload"
,
handle
);
start
();
});
equal
(
window
.
onbeforeunload
,
null
,
"window property has been unset to null/undefined"
);
doc
.
onbeforeunload
=
null
;
});
doc
.
location
.
reload
();
});
}
doc
.
location
.
reload
();
});
});
}
test
(
"jQuery.Event( type, props )"
,
function
()
{
test
(
"jQuery.Event( type, props )"
,
function
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment