Closed Bug 355213 Opened 15 years ago Closed 15 years ago

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


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

Windows XP
Not set





(Reporter: gaborca, Unassigned)





(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: Gecko/20060719 Firefox/

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">

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:
	header("Content-type: application/xhtml+xml");
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">
<html xmlns="" xml:lang="hu">
	<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>


	<div id="valami">

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

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:

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

Yes, and that bug is bug 18333.
Assignee: nobody → general
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.
Closed: 15 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.