Skip to content

Commit e488d98

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 Closes jquerygh-1583
1 parent d837f11 commit e488d98

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/css/var/getStyles.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
define(function() {
22
return function( elem ) {
3-
return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
3+
// Support: IE<=11+, Firefox<=30+ (#15098, #14150)
4+
// IE throws on elements created in popups
5+
// FF meanwhile throws on frame elements through "defaultView.getComputedStyle"
6+
if ( elem.ownerDocument.defaultView.opener ) {
7+
return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
8+
}
9+
10+
return window.getComputedStyle( elem, null );
411
};
512
});

test/unit/css.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,4 +1068,27 @@ test( "show() after hide() should always set display to initial value (#14750)",
10681068
});
10691069
}
10701070
})();
1071+
1072+
test( "Do not throw on frame elements from css method (#15098)", 1, function() {
1073+
var frameWin, frameDoc,
1074+
frameElement = document.createElement( "iframe" ),
1075+
frameWrapDiv = document.createElement( "div" );
1076+
1077+
frameWrapDiv.appendChild( frameElement );
1078+
document.body.appendChild( frameWrapDiv );
1079+
frameWin = frameElement.contentWindow;
1080+
frameDoc = frameWin.document;
1081+
frameDoc.open();
1082+
frameDoc.write( "<!doctype html><html><body><div>Hi</div></body></html>" );
1083+
frameDoc.close();
1084+
1085+
frameWrapDiv.style.display = "none";
1086+
1087+
try {
1088+
jQuery( frameDoc.body ).css( "direction" );
1089+
ok( true, "It didn't throw" );
1090+
} catch ( _ ) {
1091+
ok( false, "It did throw" );
1092+
}
1093+
});
10711094
}

0 commit comments

Comments
 (0)