Opened 9 years ago
Closed 9 years ago
#14736 closed bug (fixed)
window.getDefaultComputedStyle(elem) may return null
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | low | Milestone: | 1.12/2.2 |
Component: | css | Version: | 1.11.0 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
In Iceweasel 24.2.0 it happens here when I call layout from jQuery layout plugin in an iframe from an invisible tab (from jQuery UI tabs).
I've created this ticket after the PR:
https://github.com/rosenfeld/jquery/commit/ab632f868e620246edbc11564f4bb83b68042ed0
Change History (13)
comment:1 Changed 9 years ago by
Owner: | set to [email protected]… |
---|---|
Status: | new → pending |
comment:2 Changed 9 years ago by
Status: | pending → new |
---|
Sorry, but I don't think I'll have time to work on a project and try to replicate the issue using jQuery core only. It only seems to happen in Firefox. Please believe on me when I say that window.getDefaultComputedStyle may return null (or undefined, don't remember) for this browser.
Also, unfortunately the application I maintain is not open-source so I can't point it to you either (it's available in the web, but require user/password).
Is that really mandatory?
comment:4 Changed 9 years ago by
Status: | new → pending |
---|
I understand, we all have work to do. Yes, we need a test case to understand what is happening. We can't just add a bunch of tests for bad return values and then wonder a year later why they are there, with no way to know whether the problem is resolved. We don't need (or want!) to see the whole application or code that involves jQuery UI and third-party plugins, just a test case that shows a valid call to a jQuery core method that causes the problem.
comment:5 Changed 9 years ago by
In Firefox console I could get it to return null this way:
$('iframe:first')[0].contentWindow.getDefaultComputedStyle($('body')[0])
It doesn't matter if the element is on the parent window or in the iframe itself.
Not sure if this is a required condition, but $('iframe:first').is(':visible') returns false.
comment:6 Changed 9 years ago by
You're using the getDefaultComputedStyle
of the iframe's window but passing it the <body>
element from the parent. I wouldn't expect that to work.
comment:7 Changed 9 years ago by
Status: | pending → new |
---|
How about this? http://jsfiddle.net/b6Kv5/1/
$(function(){
var iframe = $('iframe:first')[0]; $('body').text(iframe.contentWindow.getDefaultComputedStyle(iframe.contentDocument.body));
});
It still output nulls, as I said before. It doesn't matter if the element belongs to the iframe or master, getDefaultComputedStyle from an iframe doesn't seem to work in Firefox.
comment:8 Changed 9 years ago by
And yes, the iframe being hidden is a required condition for that function to return null.
comment:9 Changed 9 years ago by
Component: | unfiled → css |
---|---|
Priority: | undecided → low |
Status: | new → open |
Ok, that's enough info for us to look into it.
comment:13 Changed 9 years ago by
Oops, I posted it too soon. The return value was wrong in the previous examples. Fixed version of workaround:
(function(){ if (window.getDefaultComputedStyle) { var old = getDefaultComputedStyle; window.getDefaultComputedStyle = function(elem) { if (var style = old(elem)) return style.display; return {display: $.css(elem, "display")}; }; } })();
comment:14 Changed 9 years ago by
Milestone: | None → 1.12/2.2 |
---|
comment:13 Changed 9 years ago by
Resolution: | → fixed |
---|---|
Status: | open → closed |
CSS: window.getDefaultComputedStyle may return null
Fixes #14736 Closes gh-1501 (cherry picked from commit 51910ba8a5aff4cd1a811f1fdb76a6c62a09a666)
Changeset: e547a2775fc79e4b2eb807da9d30719afc570458
The description sounds rather complicated. Can you post a simplified test case that only uses jQuery core? If it's only happening in one browser it could be a browser bug, but we'd need a test case to be sure. We'll also need one anyway to include in our unit tests.