Skip to main content

Bug Tracker

Side navigation

#5446 closed bug (fixed)

Opened November 03, 2009 10:12PM UTC

Closed November 07, 2009 02:56PM UTC

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:
Description

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:

=
<html>
<head>
<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"));
	}
</script>
</head>
<body>
<iframe id='iframe' onload='testSize()' src='index2.html'></iframe>
</body>
</html>
=

index2.html:

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

Thanks!

Attachments (1)
Change History (2)

Changed November 03, 2009 10:20PM UTC by bgrins comment:1

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.

Changed November 07, 2009 02:56PM UTC by john comment:2

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!