Skip to main content

Bug Tracker

Side navigation

#3546 closed bug (fixed)

Opened October 29, 2008 02:47PM UTC

Closed April 22, 2009 04:41AM UTC

Last modified August 06, 2009 10:44AM UTC

Firefox gives wrong css values for elements within IFrame (func curCSS)

Reported by: ChronoworX Owned by: brandon
Priority: major Milestone: 1.4
Component: dimensions Version: 1.2.6
Keywords: firefox iframe curcss defaultview Cc:
Blocked by: Blocking:


A document A which contains an IFrame, and a document B within this IFrame that has some CSS parameters set by use of a stylesheet declaration in the HEAD section or an external CSS file (so NOT inline).

Document A also contains some JS code (and the jQuery framework) to retrieve some CSS attributes of paragraph P in document B.


Firefox (2&3, Win & OS-x) retrieve only default values for the CSS attributes which are NOT set inline. Test case is included in the attachment. Other browsers (Opera, Safari, Webkit, IE) correctly give the values.

This error was most notisable when requesting (inner/outer)Width() or width() on element P. Firefox then does not take into account the padding, because of this.

Possible cause:

jQuery sets the defaultView variable when jQuery is first loaded to document.defaultView (or {}) (line 604). This variable is used in jQuery.curCSS to retrieve the computed CSS attribute values.

In this case, this document refers to document A and defaultView to the window document A is in. However, if the calculated CSS attribute values for element P are requested (which resides in document B), the defaultView variable still points to the defaultView (window) property of document A, which apparently in Firefox does not contain the calculated values for elements in document B.

Perhaps other browser have one central storage for calculated values, and Firefox has one per window?

Other affected code:

Perhaps the calculation in line 834 is also affected, I have not tested.

Possible fix:

I have created a fix, but it is very ugly in my view.

Replace line 868:

var computedStyle = defaultView.getComputedStyle( elem, null );


var computedStyle = (jQuery.browser.mozilla ? $(elem).parents('body')[0].parentNode.parentNode.defaultView : defaultView).getComputedStyle( elem, null );

This finds the window the element is in and uses the getComputedStyle method of that window. This makes Firefox return the correct values.

Perhaps there is a better way to find the window an element is in?

Attachments (1)
  • (30.9 KB) - added by ChronoworX October 29, 2008 02:48PM UTC.

    test case

Change History (3)

Changed October 29, 2008 11:07PM UTC by flesler comment:1

component: unfilleddimensions
owner: fleslerbrandon

Changed October 31, 2008 01:44PM UTC by ChronoworX comment:2

Just found out: my fix is not error-free in all situations.

Changed April 22, 2009 04:41AM UTC by brandon comment:3

resolution: → fixed
status: newclosed

fixed in r6317.

fortunately we can use the ownerDocument property of an element to get the document that the element lives in... then we get the correct defaultView.