Side navigation
#8763 closed bug (fixed)
Opened April 04, 2011 01:07PM UTC
Closed May 10, 2011 03:20PM UTC
Last modified June 29, 2012 11:16PM UTC
Unhandled exception: document.defaultView.getComputedStyle(div, null) is null (FF, hidden iframe)
Reported by: | Đonny | Owned by: | rwaldron |
---|---|---|---|
Priority: | blocker | Milestone: | 1.6.1 |
Component: | support | Version: | 1.5.2 |
Keywords: | regression | Cc: | |
Blocked by: | Blocking: |
Description
When there is jQuery in iframe which is hidden follwing error occurs in Firefox 4:
Error: document.defaultView.getComputedStyle(div, null) is null
Source: jquery.js
Line: 1286
It works fine in Chrome and IE8.
This is probably related to http://bugs.jquery.com/ticket/8635.
How to replicate:
see sample here: http://dzonny.cz/misc/jQueryBug/main.htm
or
--- main.html ---
... <div style="display:none"> <iframe src="iframe.htm" width="601" height="601"></iframe> </div> ...
--- iframe.html ---
... <head> <title>Iframe</title> <script src="jquery.debug.js" type="text/javascript"></script> </head> <body> <h2>Iframe</h2> <script type="text/javascript"> //<![CDATA[ $(document).ready(function () { alert('I\\'m ready!'); }); //]]> </script> </body> ...
Environment: FF4x86, Windows 7 x64
Symptoms: Error in FF JS console, alert not shown
Expected behavior: No error, alert is shown
Attachments (0)
Change History (20)
Changed April 04, 2011 01:54PM UTC by comment:1
component: | unfiled → support |
---|---|
keywords: | → regression |
priority: | undecided → blocker |
resolution: | → worksforme |
status: | new → closed |
Changed April 04, 2011 07:57PM UTC by comment:2
I'm getting this issue as well. It works in the jsfiddle but the URL Donny posted does reproduce the issue on my machine.
Firefox/3.6.16 - Intel Mac OS X 10.6
Error: document.defaultView.getComputedStyle(div, null) is null
Source File: /misc/jQueryBug/jquery.debug.js
Line: 1286
jQuery.support.reliableMarginRight = ( parseInt(document.defaultView.getComputedStyle(div, null).marginRight, 10) || 0 ) === 0;
Changed April 04, 2011 11:16PM UTC by comment:3
resolution: | worksforme |
---|---|
status: | closed → reopened |
Changed April 04, 2011 11:17PM UTC by comment:4
owner: | → rwaldron |
---|---|
status: | reopened → assigned |
Changed April 15, 2011 04:15PM UTC by comment:5
I have the same problem here. is there a hack somewhere to make it work ?
Changed April 18, 2011 11:20AM UTC by comment:6
I was able to reproduce the problem in a very specific setting: when sending a post request to an <iframe style="display:none"> (file upload), the jQuery instance inside the IFrame raises that error. A solution for that particular case is hiding the iframe by other means, i.e. negative offsets.
Changed April 19, 2011 09:53PM UTC by comment:7
_comment0: | I ran into this bug independently and narrowed it down to a minimal testcase: \ http://malaprop.org/jq/outer.html http://malaprop.org/jq/inner.html \ \ #jquery-dev helped me make a copy of it on jsfiddle: \ http://jsfiddle.net/gnarf/sBbVC/2/ → 1303250393375284 |
---|
I ran into this bug independently and narrowed it down to a minimal testcase:
http://malaprop.org/jq/outer.html http://malaprop.org/jq/inner.html
#jquery-dev helped me make a copy of it on jsfiddle:
Changed April 19, 2011 10:02PM UTC by comment:8
Also, I don't think this bug is related to #8635, it happens with 1.5.1, too.
Changed April 25, 2011 10:28PM UTC by comment:10
resolution: | → cantfix |
---|---|
status: | assigned → closed |
This is an issue I ran into while working on the default display bug. Firefox will not render "presentation" (ie. computed styles) in iframes that are display:none or are inheriting display:none.
This is a bug in Firefox, not jQuery. If it's really necessary, I will provide the IRC chat transcript with the Mozilla employee that confirmed the issue.
Changed April 27, 2011 08:21AM UTC by comment:11
Can at least some workaround be implemented, so exception is not thrown? Like
if(document.defaultView.getComputedStyle(div, null) === null) return null;
jQuery is well-known to work despite bugs in browsers.
Do you know if Mozilla is going to fix it any soon?
Changed April 27, 2011 06:41PM UTC by comment:12
_comment0: | I'll give it a run through test with all of our supported browsers, just to humour your suggestion, but the problem is that the issue cannot be fixed correctly without a lot of ugly code hacks... checking if display:none, storing that value, changing to block, getting the width/height, storing those values, setting width/height to 0 to hopefully ensure that it doesn't flash, getting the computed style you want and storing that value, restoring the previous width/height, restoring display:none ... how many DOM reflows is that? \ \ Your suggestion is just NOT return something useful if we can infer an problem with doing so, which means that your code will work in other browsers and not in Firefox. → 1303929713980475 |
---|
I'll give it a run through test with all of our supported browsers, just to humour your suggestion, but the problem is that the issue cannot be fixed correctly without a lot of ugly code hacks... checking if display:none, storing that value, changing to block, getting the width/height, storing those values, setting width/height to 0 to hopefully ensure that it doesn't flash, getting the computed style you want and storing that value, restoring the previous width/height, restoring display:none ... how many DOM reflows is that?
Your suggestion is just NOT return something useful if we can infer an problem with doing so, which means that your code will work in other browsers and not in Firefox.
Please understand that I am sympathetic to your situation.
Changed April 27, 2011 10:21PM UTC by comment:13
I was running into this too when inserting content into hidden iframes. I modified the line in the jQuery source to make sure the style object exists before attempting to get one of its properties:
jQuery.support.reliableMarginRight = document.defaultView.getComputedStyle(div, null) ? ( parseInt(document.defaultView.getComputedStyle(div, null).marginRight, 10) || 0 ) === 0 : false;
I don't know if this is better than Donny's suggestion, but I think it sets reliableMarginRight to false if the browser can't prove it should be true.
Changed May 05, 2011 09:23AM UTC by comment:14
I just upgraded to 1.6 but will now immediately downgrade to 1.4 since this bug doesn't seem to be fixed. All my uploads/interactive stuff runs in iFrames - and living without jQuery in these frames is a no can do - A real showstopper. I will retry upgrade in a month or so.
Thanks anyway! jQuery is a great layer of abstraction!
Changed May 05, 2011 02:01PM UTC by comment:15
#9054 is a duplicate of this ticket.
Changed May 05, 2011 02:02PM UTC by comment:16
resolution: | cantfix |
---|---|
status: | closed → reopened |
Changed May 05, 2011 02:03PM UTC by comment:17
milestone: | 1.next → 1.6.1 |
---|
See proposed fix in https://github.com/jquery/jquery/pull/370
Changed May 05, 2011 02:38PM UTC by comment:18
status: | reopened → open |
---|
Changed May 10, 2011 03:20PM UTC by comment:19
resolution: | → fixed |
---|---|
status: | open → closed |
Landing pull request 370. Fixes #8763.
More Details:
Changeset: 304dd618b7aa17158446bedd80af330375d8d4d4
Changed June 29, 2012 11:16PM UTC by comment:20
Just ran in this problem with 1.5.2. I see that my fix is the same as giskard22 and with it everything works as expected. So I can confirm that this is a good fix.
Does not exist with most recent build
http://jsfiddle.net/rwaldron/2heBa/