Internet Explorer XHTML window.onload issue

A

AndreHaupt

Hi,

Maybe I'm just being thick, but when my Javascript is inside the xhtml
itself it works fine:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<script type="text/javascript"> window.onload = function()
{ alert("hello"); }</script>
</head>

.....
</html>

But when I move it to an external js file, it is not executed in IE:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<script src="/javascript/common.js" type="text/javascript"></
script>
</head>
....
</html>

common.js:
window.onload = function() { alert("hello"); }

It works in Mozilla though....

Any ideas?
 
V

VK

Oh that's IE7

AFAICT it should not work on any IE because <link> element is not
properly closed:

<link rel="stylesheet" type="text/css" href="/cea/css/default.css"/

instead of

<link rel="stylesheet" type="text/css" href="/cea/css/default.css" />

unless it is a copy-n'-past error.

Besides that ensure that you are serving the page as "text/html" and
not as "application/html+xml"
IE doesn't support XHTML, so the only option is to serve it as "text/
html" so it will be parsed as a broken yet usable HTML by IE.

All fixes in place and src attribute pointing to the right location, a
page served as "text/html"

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Construction Economics Associates</title>
<link rel="stylesheet" type="text/css"
ref="/cea/css/default.css" />
<script src="/javascript/common.js" type="text/javascript">
</script>
</head>
<body>
</body>
</html>

will run just fine.
 
T

Thomas 'PointedEars' Lahn

AndreHaupt said:
Oh that's IE7

Microsoft Internet Explorer does not support XHTML natively to date, nor is
XHTML required here. Serve HTML 4.01 as text/html and many problems will go
away.

You should also use the standardized intrinsic event handler `onload'
attribute of the `body' element instead of the proprietary event handler
property `onload' of the host object referred to by the host-defined
`window' property of the Global Object (or another object in the scope chain).

BTW, ignore VK.


PointedEars
 
V

VK

You should also use the standardized intrinsic event handler `onload'
attribute of the `body' element instead of the proprietary event handler
property `onload'

A very bad advise from the point of view of content-layout-scripting
separation: to hardcode some function call into HTML/XHTML tags. What
exactly standardization body does suggest such approach?
 
T

Thomas 'PointedEars' Lahn

VK said:
A very bad advise from the point of view of content-layout-scripting
separation:

Nonsense. Whether either the `script' element contains an assignment of a
reference to a Function object to `window.onload' (or performing an
equivalent), or the `script' element to contain a function declaration and
the `onload' property of the `body' element to contain a call to that
function makes no real difference. The script is always tied to and
tailored to the markup.

The real difference here is that the `onload' property is proprietary, and
both it and a standards-compliant equivalent would require feature-testing
for themselves, while the `onload' attribute is standardized as per HTML
4.01 (and supported long before that) and requires no feature-testing on itself.


PointedEars
 
V

VK

You should also use the standardized intrinsic event handler `onload'
Nonsense. Whether either the `script' element contains an assignment of a
reference to a Function object to `window.onload' (or performing an
equivalent), or the `script' element to contain a function declaration and
the `onload' property of the `body' element to contain a call to that
function makes no real difference. The script is always tied to and
tailored to the markup.

Nonsense. :)

<body onload="someFunction()"> for each and any script on the page
will try to launch someFunction and it better be in the script and
really being the one needed onload. This way you create a hardcoded
link between your HTML structure and your script structure. In some
organizations it can be a conversion about the onload function name,
say Java-inspired init() as in my company but there is not such
convention on any wide run.
The real difference here is that the `onload' property is proprietary, and
both it and a standards-compliant equivalent would require feature-testing
for themselves

Double nonsense unless NN4 or lower is a requirement. However I liked
NN I said goodbye to it long ago, so all other descent people did.
 
A

AndreHaupt

AFAICT it should not work on any IE because <link> element is not
properly closed:

<link rel="stylesheet" type="text/css" href="/cea/css/default.css"/

instead of

<link rel="stylesheet" type="text/css" href="/cea/css/default.css" />

unless it is a copy-n'-past error.

Besides that ensure that you are serving the page as "text/html" and
not as "application/html+xml"
IE doesn't support XHTML, so the only option is to serve it as "text/
html" so it will be parsed as a broken yet usable HTML by IE.

All fixes in place and src attribute pointing to the right location, a
page served as "text/html"

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Construction Economics Associates</title>
<link rel="stylesheet" type="text/css"
ref="/cea/css/default.css" />
<script src="/javascript/common.js" type="text/javascript">
</script>
</head>
<body>
</body>
</html>

will run just fine.

Just a copy-and-paste error yes.

I'll try your suggestions thanks.
 
A

AndreHaupt

Nonsense. Whether either the `script' element contains an assignment of a
reference to a Function object to `window.onload' (or performing an
equivalent), or the `script' element to contain a function declaration and
the `onload' property of the `body' element to contain a call to that
function makes no real difference. The script is always tied to and
tailored to the markup.

The real difference here is that the `onload' property is proprietary, and
both it and a standards-compliant equivalent would require feature-testing
for themselves, while the `onload' attribute is standardized as per HTML
4.01 (and supported long before that) and requires no feature-testing on itself.

PointedEars


I have considered moving back to 4.01, but I get layout issues (DIV
positioning).

I'll find some midway between the two. Thanks for your reply.
 
T

Thomas 'PointedEars' Lahn

AndreHaupt said:
The real difference here is that the `onload' property is proprietary, and
both it and a standards-compliant equivalent would require feature-testing
for themselves, while the `onload' attribute is standardized as per HTML
4.01 (and supported long before that) and requires no feature-testing on itself.
[...]

I have considered moving back to 4.01, but I get layout issues (DIV
positioning).

Probably you have done something else wrong. Anyhow, XHTML 1.0 also
provides the `onload' attribute, of course. So that alone is no sufficient
reason to use HTML 4.01 in favor of XHTML 1.x; however, insufficient XHTML
support, as I pointed out earlier, is.
I'll find some midway between the two.

You can't have both. HTML-compatible XHTML is an illusion.
Thanks for your reply.

You're welcome.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top