Closed Bug 355213 Opened 18 years ago Closed 18 years ago

In XHTML sent with application/xhtml+xml, offsetWidth is calculated only on window.onload event

Categories

(Core :: DOM: Core & HTML, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: gaborca, Unassigned)

References

()

Details

Attachments

(2 files)

User-Agent:       Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 1.1.4322)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; hu; rv:1.8.0.5) Gecko/20060719 Firefox/1.5.0.5

If you serve your XHTML with text/html mime type, you can use offsetWidth on all elements before the page is fully loaded, for example:
...
<script type="text/javascript">
alert(document.getElementById('something').offsetWidth;
</script>
</body>
</html>

When served with mimetype application/xhtml+xml, offsetWidth = 0 in these cases, it only works well in window.onload event.

Reproducible: Always

Steps to Reproduce:
<?php
	header("Content-type: application/xhtml+xml");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="hu">
<head>
	<title></title>
	<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=iso-8859-2" />
	<link type="text/css" rel="stylesheet" href="css/xhtml.css" />
	<script type="text/javascript" src="js/xhtml.js"></script>
</head>

<body>

	<div id="valami">
		asdfg
	</div>

<script type="text/javascript">alert(document.getElementById('valami').offsetWidth);</script>

</body>
</html>
Actual Results:  
alerted result: 0

Expected Results:  
alerted result: 220
in xhtml.css:

#valami {
	position: absolute;
	left: 100px;
	top: 100px;
	width: 200px;
	height: 200px;
	padding: 10px;
	background: red;
}
bz: Should this bug here depend on Bug 18333 (I'm not sure if that bug will help this bug here)?
Thanks for the answer. This bug is maybe connected to 18333, but I think it is mainly because of a basic bug of Mozilla, described here:
http://www.mozilla.org/docs/web-developer/faq.html#xhtmldiff

"The document is not loaded and rendered incrementally. That is, the document is displayed only after the entire document has been received and parsed. Contrary to a common misguided assertion, this is not done in response to a requirement set forth in any W3C specification. In particular, the XML specification does not require the entire document to be checked for errors before rendering can start. The lack of incremental loading and display is simply a bug (or a missing feature)."

I think this because when I use the DOMContentLoaded event, offsetWidth etc. work.
Yeah, this depends on bug 18333.

> but I think it is mainly because of a basic bug of Mozilla, described here:
> http://www.mozilla.org/docs/web-developer/faq.html#xhtmldiff

Yes, and that bug is bug 18333.
Assignee: nobody → general
Status: UNCONFIRMED → NEW
Component: General → DOM: HTML
Depends on: incrementalxml
Ever confirmed: true
Product: Firefox → Core
QA Contact: general → ian
Version: unspecified → Trunk
WFM on Mac, even in the 2007-01-29 trunk nightly (before the fix for bug 18333 landed).
Attached file Testcase
This shows the problem for me in pre-18333 builds.
Checked in the test.  This is fixed.
Status: NEW → RESOLVED
Closed: 18 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Component: DOM: HTML → DOM: Core & HTML
QA Contact: ian → general
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: