IE no doing "onload" function?

R

Richard Cornford

Now that I've thought about it for a little while, I
don't think so (I don't think it's wrong for an xhtml
element to be closed that way...

It is not wrong for an XHTML tag to end like that, it is a standard XML
shorthand for an element that has no content. The problem is that your
document is not really XHTML, at lest the browsers don't think it is and
there opinion of the document determines how they handle it.
and neither do the validation tools I've been using, which
do validate xhtml differently than html).

As they should, but validators do not always apply the same criteria to
deciding which type a document is as browsers apply.
I don't know why you would call my xhtml file only an
"illusion" of being xhtml, either... it's got all
the appropriate tags for xhtml.

I call it the illusion of XHTML because it looks like XHTML to one
observer and looks like (error filled, so tag soup) HTML to another (the
browser). Illusion seems a reasonable term to apply to a misleading
appearance.

Because our subject here is javascript, so mostly the scripting of the
object model provided by web browsers, we see the manifestation of the
difference between an HTML document and an XHTML document in the DOM
created by the browser to be scripted.

Presented with (what it thinks is) an HTML document a browser will
create an HTML DOM to be scripted. An HTML DOM uses case insensitive tag
names, is unaware of namespaces, prefers the direct assignment to
element properties over the setAttribute method and provides numerous
traditional features and shortcuts. While a browser presented with what
it perceives as an XHTML document (if it supports XHTML at all) will
create an XHTML DOM instead. The XHTML DOM uses case sensitive tag
names, has in interest in namespaces, prefers setAttribute(NS) over
direct assignment to Element properties and tends not to support
shortcuts, features and convenience properties that are not formally
specified. They also do not implement some features that do not fit well
with XML parsing, such as not supporting the - document.write(ln) -
method.

Generally, very few non-trivial browser scripts are capable of
successfully operating with both types of DOM (and writing single
scripts that will introduces an entire extra level of testing and
branching on top of that normally required for cross-browser scripting).

This makes it very important for script authors to be very clear about
what type of DOM is going to be created by the browser, and so very
important to understand the browser's attitude towards the documents it
receives. The browser sees through the illusion of XHTML and so we must
also see through that illusion in order not to be fooling ourselves into
scripting the wrong type of DOM.

Web browsers almost entirely make their decision as to which type of
document they are receiving based upon the HTTP content-type header.
Which, from the point of view of an HTTP user agent, is the only
reasonable criteria. If a document is served to them with a content-type
of (or including) text/html they assume that the document is HTML and
treat it as such (passing it into their HTML parser and crating an HTML
DOM). Even if the mark-up in the document resembles (or even validates
as) XHTML the browser will still treat it as HTML, and so apply its tag
soup error correction rules to fix all the XML oddities it encounters in
what it is assuming is HTML mark-up (or at least as many as it can).

If a document is served with an XHTML content type (usually the
recommended application/xhtml+xml), if it can, the browser will
interpret the document as XHTML and create an XHTML DOM to be scripted.

Loading your page into Mozilla (which supports XHTML and so can create
an XHTML DOM if it sees the document as XHTML) and opening the "page
info" dialog shows your content type header as:-

content-type text/html; charset=iso-8859-1

- and lists the type as "text/html". Showing that even a browser that
can understand XHTML is seeing the document as HTML. This is why your
XHTML is an illusion; you see it that way but you have not convinced the
browsers.

Of course IE doesn't understand XHTML at all so it will never interpret
a document as XHTML, and cannot build an XHTML DOM at all. IE tends to
offer the user the opportunity to save documents served as
application/xhtml+xml to disc rather than even attempt to display them.
Now, as for the javascript problem, it seems you are correct
- IE doesn't understand the the closing / at the end of the
<script> tag.

Without being able to see your source code (and in this case without
being able to access it online to verify the HTTP headers) that was a
guess on my part. A possibility that could fully explain the symptoms
described. There was nothing in your original post to suggest an attempt
to use XHTML at all.
It does work when I put </script> instead... but I would
hardly call the way I did it an error. Again, neither do
the validation tools.

The problem with the vaidators is that they recognise what is called
"Appendix C XHTML 1.0" as XHTML. Appendix C describes a set of rules to
facilitate serving XHTML style mark-up to web browsers that do not
understand XHTML. It includes the proposal that such documents may be
served as text/html, as they must if the non-XHTML browsers like IE are
to render such documents at all.

The problem is that because it allows (superficially) XHTML documents to
be served as text/html, appendix C acts to convince authors that they
are working with XHTML when the browser at the receiving end still
thinks it is receiving HTML. Appendix C is effectively a set of rules
for the creation of formally malformed HTML, where the malformations are
within the HTML browsers ability to error correct and the whole result
is well-formed XML and XHTML mark-up (so can be validated as XHTML).
Confusion and misconceptions follow from this situation, but as script
authors we cannot afford to be taken in. We must see through all this
and take the position that the real type of a document is the type that
the browser thinks it is, because that will then the type of DOM we will
be scripting.
That to me says that it's another one of the many browser
problems out there because IE doesn't understand a perfectly
valid closing tag for an xhtml document.

IE does not support XHTML at all, it is an HTML web browser and
Microsoft have never claimed anything different.

So, while I have a solution, to me it's another IE bug
(not that other browsers don't have them), unless I'm
missing something.
<snip>

I hope that you have now seen why I speak of the illusion of XHTML, and
that your were missing something; that the document is an HTML document
in reality and so IE's interpretation of the SCRIPT tag is not
unreasonable.

Richard.
 
T

Thomas 'PointedEars' Lahn

Well, being anal retentive, actually, they should implement the correct
parser regardless of what's widely available, otherwise standards
become meaningless. Just my $0.02.

But they do; take the W3C Validator as an example. In absence of the
correct/recommended media type declaration such as here, the parser to be
used to parse (and validate) the markup should be determined by evaluating
the prolog of the document, particularly the DOCTYPE declaration.
In other words, I'd rather my document not render correctly (but good
enough) in one or two UAs now if, in the future, they complied and
rendered them correctly... just so long as it wasn't too bad, at least.

You are confusing the issue. It is you (serving XHTML as text/html) and
the UAs (parsing XHTML as wrongfully error-corrected HTML if served as
text/html) that have a problem, not the validators (that I know of).


PointedEars
 
T

Thomas 'PointedEars' Lahn

Thomas said:
When IE or another UA is served an XHTML resource as text/html, the tag
soup parser used for HTML is also used for XHTML. It is a tag soup
parser, because if it was an HTML parser it would follow SGML rules. The
SGML declaration of HTML enables the SHORTTAG feature, that is, <.../>
strictly equals <...>&gt; in HTML. A tagsoup parser does not implement
this feature, but wrongfully error-corrects it to <...>. [...]

This can be misunderstood, for it does not apply to /any/ other UA. There
are UAs out there that (at least partially) implement SHORTTAG correctly,
and therefore (at least to a point) cannot be considered to use a tag soup
parser. Which is one reason why serving XHTML as text/html is considered
harmful.

See also: [de] <URL:http://dodabo.de/html+css/tests/shorttag.html>


PointedEars
 
V

VK

Now that I've thought about it for a little while, I don't think so (I
don't think it's wrong for an xhtml element to be closed that way...
and neither do the validation tools I've been using, which do validate
xhtml differently than html). I don't know why you would call my xhtml
file only an "illusion" of being xhtml, either... it's got all the
appropriate tags for xhtml.

So that was the issue? You used
<script type="text/javascript src="myScript.js" />
syntax and it failed to work?

In this case it looks like a trolling OP (sorry to say) because:

1) This vital part of the problem was left for guessing.
2) It was stated that <q>It does't work in my IE (6), but works fine in
Firefox</q> which is a clear provocation: it doesn'r work in /neither/
browser if served as text/html
It will work on XHTML-aware browsers if served with proper content type
like application/xhtml+xml. But in such case you would also mention a
strange behavior on IE (Save As prompt instead of page display). And if
you do some UA / Accept header sniffing server-side and set
Content-Type accordingly, you /have/ to mention it clearly in OP.

So the right question (not a call for guessing) would be like:
<script type="text/javascript src="myScript.js" /> wich is proper XHTML
syntax works fine for Firefox if page is served as
application/xhtml+xml
At the same time it doesn't work (ignored) if the page is served as
text/html. It doesn't work in neither case on IE. What is the problem?

In this case no one would have to guess and restore your situation and
you would be pointed right away to one of discussions like
<http://groups.google.com/group/comp..._frm/thread/6ff8329925aae8a6/cc7ca3f2132c0416>
with test results like
<http://groups.google.com/group/comp...5aae8a6/f3d25d58d6adcfea#doc_32017f7edac4940d>
 
F

fred.haab

VK said:
So that was the issue? You used
<script type="text/javascript src="myScript.js" />
syntax and it failed to work?

In this case it looks like a trolling OP (sorry to say) because:

Well, if my xhtml document is only an illusion, then so is your guess.
I had no idea something that I thought was supposed to parse an xml
style couldn't handle a proper closing tag. The book I'm referencing
on the subject, "Web Desgin in a Nutshell", encourages use of xhtml 1.0
strict or xhtml 1.1, but I must have missed the part where she said
"but IE doesn't parse xhtml correctly." Now I know.
 
T

Thomas 'PointedEars' Lahn

I had no idea something that I thought was supposed to parse an xml
style couldn't handle a proper closing tag. The book I'm referencing
on the subject, "Web Desgin in a Nutshell", encourages use of xhtml 1.0
strict or xhtml 1.1,

but I must have missed the part where she said
"but IE doesn't parse xhtml correctly." Now I know.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
That is an understatement. If it was only incorrect parsing, one could
work around that. IE simply does not support XHTML (let alone HTML), and
that is not going to change for the foreseeable future. Because IE 7 that
was announced to /finally/ fix the numerous flaws IE 6 had, still does not
support XHTML (to my knowledge -- prove me wrong![1]), while all other
widely distributed browsers do more or less (with Geckos being the foremost
UAs in this field).


PointedEars
___________
[1] <URL:http://pointedears.de/scripts/test/dom.xhtml?strict>
 
R

Richard Cornford

VK said:
So that was the issue? You used
<script type="text/javascript src="myScript.js" />
syntax and it failed to work?

In this case it looks like a trolling OP (sorry to say)
because:

1) This vital part of the problem was left for guessing.

You are accusing someone of trolling because they did not provide
complete context information in their original post? That attitude would
designate 80% plus of the OPs in this group trolls.

Are you sure you are not over reacting to having embarrassed yourself so
spectacularly, yet again?
2) It was stated that <q>It does't work in my IE (6), but
works fine in Firefox</q> which is a clear provocation: it
doesn'r work in /neither/ browser if served as text/html

Not true. Mozilla's tag-soup error correction has been modified to
accommodate this. That change will probably serve to make the illusion
of XHTML in text/html documents even harder to spot for page authors but
it does go along with the 'what you accept' side of 'be strict in what
you send and tolerant in what your accept'. XHTML has made that error
more prevalent in HTML documents so it is not surprising when
error-correction is updated to accommodate it.

So the right question (not a call for guessing) would
be like:
<script type="text/javascript src="myScript.js" /> wich
is proper XHTML syntax works fine for Firefox if page is
served as application/xhtml+xml
At the same time it doesn't work (ignored) if the page is
served as text/html. It doesn't work in neither case on
IE. What is the problem?

The FAQ already provides better advice on the effective asking of
questions that anything you could suggest. And of course the pages being
served as application/xhtml+xml is an irrelevance in this situation
(they never were being served as such) and so should not be erroneously
stated.
In this case no one would have to guess ...

Whether or not it should be necessary to guess, your mistake here (and
in the many similar situations) was to guess without reading or
understanding the symptoms described. If you looked at the code and the
infuriation provided as observed that the code could not produce the
symptoms described then an appropriate response would be to point that
out, and imply that more information would be necessary.

Instead you elected to make a spurious, 'mystical incantation'
suggestion that neither addressed the issue nor explained the symptoms.
Not understanding javascript at all you are doomed to do that, but there
is no point calling the OP names because you cannot practice joined-up
thinking.

Richard.
 
R

Richard Cornford

Richard Cornford wrote:
... . If you looked at the code and the infuriation
provided as observed that the code could not produce
the symptoms described ...
<snip>

That should have read "... the code and the information provided and
observed ...".

Richard.
 
V

VK

Well, if my xhtml document is only an illusion, then so is your guess.
I had no idea something that I thought was supposed to parse an xml
style couldn't handle a proper closing tag. The book I'm referencing
on the subject, "Web Desgin in a Nutshell", encourages use of xhtml 1.0
strict or xhtml 1.1, but I must have missed the part where she said
"but IE doesn't parse xhtml correctly." Now I know.

You are still missing another very important part: even if UA supports
XHTML, it doesn't treat an XHTML page (however perfectly valid it would
be) as XHTML /unless/ such page is served with the corresponding
Content-Type application/xhtml+xml.
If it's served with Content-Type text/html, it is treated as HTML with
extra trash to ignore in some tags.
Note: Content-Type has to be set by server, not in HTTP-EQUIV meta on
the page itself, because server header has higher priority.

HTTP protocol doesn't give a damn about what do you /think/ the
document is. So the regular "powerful spells" like

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

have the effect (an absence of such more precisely) as

<!-- IT IS TRULLY DEEPLY VALID XHTML PAGE
ANY UA SUPPORTING XHTML IS REQUIRED
TO TREAT THIS PAGE WITH FULL RESPECT AS XHTML.
ALL VIOLATIONS WILL BE PROSECUTED BY W3C POLICE -->
<html>
// the rest of your page

Both set of "spells" would have no effect without proper Content-Type.
The fact that this is not clearly stated in your book suggests to
switch on some other book.
 
F

fred.haab

VK said:
You are still missing another very important part: even if UA supports
XHTML, it doesn't treat an XHTML page (however perfectly valid it would
be) as XHTML /unless/ such page is served with the corresponding
Content-Type application/xhtml+xml.
If it's served with Content-Type text/html, it is treated as HTML with
extra trash to ignore in some tags.
Note: Content-Type has to be set by server, not in HTTP-EQUIV meta on
the page itself, because server header has higher priority.

Yes, that is what I was missing, and that explains a lot.
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top