aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Gaidarenko <markelog@gmail.com>2014-05-18 20:47:37 +0400
committerOleg Gaidarenko <markelog@gmail.com>2014-06-16 03:08:26 +0400
commite488d985cfb10ab8c684bbc6a9b8ff3eae23bf83 (patch)
tree46cc46f9520895671ac5432c69ce1f2fd60aff76
parentd837f119c3729565103005d5d7fa89e1dd8110cb (diff)
downloadjquery-e488d985cfb10ab8c684bbc6a9b8ff3eae23bf83.tar.gz
jquery-e488d985cfb10ab8c684bbc6a9b8ff3eae23bf83.zip
CSS: Do not throw on frame elements in FF
IE9-10 throws on elements created in popups (see #14150), FF meanwhile throws on frame elements through "defaultView.getComputedStyle" (see #15098) Use "defaultView" if in the popup which would fix IE issue, use "window.getComputedStyle" which would fix FF issue. And everybody wins, except performance, but who cares right? Fixes #15098 Closes gh-1583
-rw-r--r--src/css/var/getStyles.js9
-rw-r--r--test/unit/css.js23
2 files changed, 31 insertions, 1 deletions
diff --git a/src/css/var/getStyles.js b/src/css/var/getStyles.js
index 26cc0a25e..413acd04a 100644
--- a/src/css/var/getStyles.js
+++ b/src/css/var/getStyles.js
@@ -1,5 +1,12 @@
define(function() {
return function( elem ) {
- return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
+ // Support: IE<=11+, Firefox<=30+ (#15098, #14150)
+ // IE throws on elements created in popups
+ // FF meanwhile throws on frame elements through "defaultView.getComputedStyle"
+ if ( elem.ownerDocument.defaultView.opener ) {
+ return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
+ }
+
+ return window.getComputedStyle( elem, null );
};
});
diff --git a/test/unit/css.js b/test/unit/css.js
index bfbe8ae5e..58f43143a 100644
--- a/test/unit/css.js
+++ b/test/unit/css.js
@@ -1068,4 +1068,27 @@ test( "show() after hide() should always set display to initial value (#14750)",
});
}
})();
+
+test( "Do not throw on frame elements from css method (#15098)", 1, function() {
+ var frameWin, frameDoc,
+ frameElement = document.createElement( "iframe" ),
+ frameWrapDiv = document.createElement( "div" );
+
+ frameWrapDiv.appendChild( frameElement );
+ document.body.appendChild( frameWrapDiv );
+ frameWin = frameElement.contentWindow;
+ frameDoc = frameWin.document;
+ frameDoc.open();
+ frameDoc.write( "<!doctype html><html><body><div>Hi</div></body></html>" );
+ frameDoc.close();
+
+ frameWrapDiv.style.display = "none";
+
+ try {
+ jQuery( frameDoc.body ).css( "direction" );
+ ok( true, "It didn't throw" );
+ } catch ( _ ) {
+ ok( false, "It did throw" );
+ }
+});
}