defer attribute on script element not working in firefox 1.0

P

pantagruel

The following does not work in firefox:

<script defer="defer">





var x=document.getElementsByName("repositoryNamespace")
alert(x.length + " elements!")
</script>

</head>



<body id="www.interoperabilityframework.info">
<a name="repositoryNamespace"></a>


</body></html>

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.

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.
 
P

pantagruel

well I've gone ahead and used the window.onload event to call my
script, would still like to have a defer attribute that worked however.
 
M

Michael Winter

The following does not work in firefox:

<script defer="defer">

It won't effect execution, however the type attribute is required. In
a HTML document, the above should be

<script type="text/javascript" defer>

As for whether defer "works" or not, the attribute is only a hint. In
fact, all the hint means is "this script won't modify the document".
Without it, a user agent must execute the script immediately because
it might have to output data to the document stream. With it, the user
agent can do what it likes: parse the script immediately, or ignore it
until a more convenient time. It doesn't mean "wait until the document
is loaded". That's what the load event is for.

[snip]

Mike
 
F

Fred Oz

pantagruel said:
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."

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.
 

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,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top