pantagruel wrote:
The following does not work in firefox:
<script defer="defer">
Exactly what does 'work' mean to you? Here is what the HTML
spec says:
"When set, this boolean attribute provides a hint to the user
agent that the script is not going to generate any document
content (e.g., no "document.write" in javascript) and thus,
the user agent can continue parsing and rendering."
<URL:http://www.w3.org/TR/html4/interact/scripts.html#adef-defer>
var x=document.getElementsByName("repositoryNamespace" )
alert(x.length + " elements!")
</script>
</head>
[...]
I have also tried the following:
<script src="reference.js" defer="defer">
</script>
</head>
<body id="www.interoperabilityframework.info">
<a name="repositoryNamespace"></a>
which does not work either, except for in IE.
Again, depends on your idea of what 'does not work'.
I have tried without defer="defer" and just having defer on the
element,
I have tried with defer = True or true.
I have tried it with and without a dtd.
IE seems to accept everything, Firefox nothing.
Interestingly enough, using the xhtml 1.0 dtd Firefox accepted an
onLoad attribute on the body. But gee, I don't want to use the onLoad
attribute, I want to defer the script.
You infer that the 'defer' attribute should stop the script from
being parsed until after the document has finished loading, but
the HTML 4.01 spec does not say that.
The way I read it, defer says the browser *may* defer processing
the script and to start parsing subsequent elements because the
script does not, in the programmer's opinion, affect document
layout.
It is by no means a directive to leave the script until after
the page has load.
If you want the behaviour of onload, use onload. Don't expect
defer to do what you want simply because it's what you want.
Have you considered putting your script into the document body,
just below the element it refers to?
<body id="www.interoperabilityframework.info">
<a name="repositoryNamespace"></a>
<script type="text/javascript">
var x=document.getElementsByName("repositoryNamespace" )
alert(x.length + " elements!")
</script>
Note that x.length should only ever be either 0 or 1, as the
name attribute on 'a' elements must be unique in the document
and shares the same namespace as the id attribute.
--
Fred