Bug Tracker

Modify

Ticket #3546 (closed bug: fixed)

Opened 5 years ago

Last modified 4 years ago

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:
Blocking: Blocked by:

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

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

Change History

Changed 5 years ago by ChronoworX

test case

comment:1 Changed 5 years ago by flesler

  • Owner changed from flesler to brandon
  • Component changed from unfilled to dimensions

comment:2 Changed 5 years ago by ChronoworX

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

comment:3 Changed 4 years ago by brandon

  • Status changed from new to closed
  • Resolution set to fixed
  • Milestone changed from 1.3 to 1.3.3

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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.