Skip to content

Commit 76294e1

Browse files
committed
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 Ref e488d98
1 parent d05f4bd commit 76294e1

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/css/curCSS.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ var getStyles, curCSS,
1111

1212
if ( window.getComputedStyle ) {
1313
getStyles = function( elem ) {
14-
return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
14+
// Support: IE<=11+, Firefox<=30+ (#15098, #14150)
15+
// IE throws on elements created in popups
16+
// FF meanwhile throws on frame elements through "defaultView.getComputedStyle"
17+
if ( elem.ownerDocument.defaultView.opener ) {
18+
return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
19+
}
20+
21+
return window.getComputedStyle( elem, null );
1522
};
1623

1724
curCSS = function( elem, name, computed ) {

test/unit/css.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,4 +1126,27 @@ test( "show() after hide() should always set display to initial value (#14750)",
11261126
});
11271127
}
11281128
})();
1129+
1130+
test( "Do not throw on frame elements from css method (#15098)", 1, function() {
1131+
var frameWin, frameDoc,
1132+
frameElement = document.createElement( "iframe" ),
1133+
frameWrapDiv = document.createElement( "div" );
1134+
1135+
frameWrapDiv.appendChild( frameElement );
1136+
document.body.appendChild( frameWrapDiv );
1137+
frameWin = frameElement.contentWindow;
1138+
frameDoc = frameWin.document;
1139+
frameDoc.open();
1140+
frameDoc.write( "<!doctype html><html><body><div>Hi</div></body></html>" );
1141+
frameDoc.close();
1142+
1143+
frameWrapDiv.style.display = "none";
1144+
1145+
try {
1146+
jQuery( frameDoc.body ).css( "direction" );
1147+
ok( true, "It didn't throw" );
1148+
} catch ( _ ) {
1149+
ok( false, "It did throw" );
1150+
}
1151+
});
11291152
}

0 commit comments

Comments
 (0)