Bug Tracker

Opened 11 years ago

Closed 11 years ago

#5446 closed bug (fixed)

css("font-size") not returning correct value for elements in iframe

Reported by: bgrins Owned by:
Priority: major Milestone: 1.4
Component: core Version: 1.3.2
Keywords: iframe getcomputedstyle css Cc:
Blocked by: Blocking:


The code seems to use a cached defaultView that is document.defaultView. Inside the curCSS function it should set defaultView = elem.ownerDocument.defaultView.

I have attached a patch that fixes the problem - let me know if you need anything else.

Here is a simple test case:

========== index.html: ==========

<script type='text/javascript' src='jquery-1.3.2.js'></script>
<script type='text/javascript'>
	function testSize() {
		var doc = $("#iframe").contents()[0];
		var $h1 = $(doc.body).find("h1:not(.big)");
		var $h1Big = $(doc.body).find("h1.big");
		alert("Should not be the same: " + $h1.css("font-size") + " == " + $h1Big.css("font-size"));
<iframe id='iframe' onload='testSize()' src='index2.html'></iframe>

========== index2.html: ==========

<style type='text/css'>
.big { font-size: 1.2em; }
<h1>Normal Heading</h1>
<h1 class='big'>Big Heading</h1>


Attachments (1)

curCSSDefaultView.patch (450 bytes) - added by bgrins 11 years ago.
Patch for curCSS Ticket #5446

Download all attachments as: .zip

Change History (3)

Changed 11 years ago by bgrins

Attachment: curCSSDefaultView.patch added

Patch for curCSS Ticket #5446

comment:1 Changed 11 years ago by bgrins

Also, I forgot to mention that this is an error in Firefox. I am using FF 3.5.4 but I am certain that it is an error in all versions of that browser. It seems to currently work in Safari, Chrome, and Internet Explorer.

I have ran into a few jQuery bugs that have to do with not using the ownerDocument. I will document them and submit patches for them all sometime soon.

comment:2 Changed 11 years ago by john

Component: unfilledcore
Resolution: fixed
Status: newclosed

I think you made a mistake with your patch - you define the defaultView but then never reference it any where.

The one case where getComputedStyle is used it already accesses the correct one on the document:

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

It looks like you're doing this patch against an old version of jQuery - so, incidentally, this will be fixed in jQuery 1.4!

Note: See TracTickets for help on using tickets.