By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,106 Members | 2,474 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,106 IT Pros & Developers. It's quick & easy.

defer attribute on script element not working in firefox 1.0

P: n/a
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.

Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.

Jul 23 '05 #2

P: n/a
On 21/03/2005 10:22, pantagruel wrote:
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

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3

P: n/a
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
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.