aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Methvin <dave.methvin@gmail.com>2013-04-08 21:33:25 -0400
committerDave Methvin <dave.methvin@gmail.com>2013-04-08 21:52:16 -0400
commitfdaf2146adae861ed3c3a42f0044e589e9d86afd (patch)
tree23f267675158df211f7e654a0a8ac4823c27aee2
parent08e57b1de728510de008acb25f7d75f0a20b78bc (diff)
downloadjquery-fdaf2146adae861ed3c3a42f0044e589e9d86afd.tar.gz
jquery-fdaf2146adae861ed3c3a42f0044e589e9d86afd.zip
Fix #13393. Avoid IE9 activeElement of death.
(Cherry picked from 85fc5878b3c6af73f42d61eedf73013e7faae408) Conflicts: src/event.js
-rw-r--r--src/event.js10
-rw-r--r--test/data/event/focusElem.html16
-rw-r--r--test/unit/event.js5
3 files changed, 29 insertions, 2 deletions
diff --git a/src/event.js b/src/event.js
index fae4f0765..5151d2bd7 100644
--- a/src/event.js
+++ b/src/event.js
@@ -12,6 +12,12 @@ function returnFalse() {
return false;
}
+function safeActiveElement() {
+ try {
+ return document.activeElement;
+ } catch ( err ) { }
+}
+
/*
* Helper functions for managing events -- not part of the public interface.
* Props to Dean Edwards' addEvent library for many of the ideas.
@@ -555,7 +561,7 @@ jQuery.event = {
focus: {
// Fire native event if possible so blur/focus sequence is correct
trigger: function() {
- if ( this !== document.activeElement && this.focus ) {
+ if ( this !== safeActiveElement() && this.focus ) {
try {
this.focus();
return false;
@@ -570,7 +576,7 @@ jQuery.event = {
},
blur: {
trigger: function() {
- if ( this === document.activeElement && this.blur ) {
+ if ( this === safeActiveElement() && this.blur ) {
this.blur();
return false;
}
diff --git a/test/data/event/focusElem.html b/test/data/event/focusElem.html
new file mode 100644
index 000000000..eed082c1a
--- /dev/null
+++ b/test/data/event/focusElem.html
@@ -0,0 +1,16 @@
+<!doctype html>
+<html>
+<head>
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
+ <title>.focus() (activeElement access #13393)</title>
+
+ <script src="../../jquery.js"></script>
+</head>
+<body>
+ <a href="#" id="frame-link"></a>
+ <script>
+ jQuery("#frame-link").focus();
+ window.parent.iframeCallback( true );
+ </script>
+</body>
+</html> \ No newline at end of file
diff --git a/test/unit/event.js b/test/unit/event.js
index 824997d77..4f2bb7004 100644
--- a/test/unit/event.js
+++ b/test/unit/event.js
@@ -2489,6 +2489,11 @@ testIframeWithCallback( "jQuery.ready promise", "event/promiseReady.html", funct
ok( isOk, "$.when( $.ready ) works" );
});
+testIframeWithCallback( "Focusing iframe element", "event/focusElem.html", function( isOk ) {
+ expect(1);
+ ok( isOk, "Focused an element in an iframe" );
+});
+
// 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 ) {