Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 10 years ago

#3546 closed bug (fixed)

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:

Description

Setup:

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.

Bug:

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 );

With: 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)

ticket_3546.zip (30.9 KB) - added by ChronoworX 11 years ago.
test case

Download all attachments as: .zip

Change History (4)

Changed 11 years ago by ChronoworX

Attachment: ticket_3546.zip added

test case

comment:1 Changed 11 years ago by flesler

Component: unfilleddimensions
Owner: changed from flesler to brandon

comment:2 Changed 11 years ago by ChronoworX

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

comment:3 Changed 11 years ago by brandon

Milestone: 1.31.3.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.

Note: See TracTickets for help on using tickets.