Google
 
Web smallbusinessbrief.com

View Full Version : HTML4.0 and Javascript


StupidScript
11th August 2004, 06:53 PM
[Comment moved from SEO Checklist by StupidScript]

About the only thing the HTML4 DTD has to do with Javascript is the way the <script> tag is written. Javascript is a separate technology (developed by Netscape and not related to Sun's Java except for marketing reasons).

The tag should look like one of these, when it's finished:

<script language="javascript" type="text/javascript">
functions andStuff() {
}
</script>

--- or ---

<script language="javascript" type="text/javascript" src="site.js"></script>

--- or ---

<script language="javascript" type="text/javascript" src="site.js" defer=1></script>

(The last one tells the browser that you won't be using Javascript to write anything on the page ( i.e. document.write() ) so it can go ahead and render the page without waiting.)

Sometimes you see the version of Javascript in the "language" attribute ( i.e. language="Javascript1.2" ), but it makes no difference to the browser. In fact, the "language" attribute is deprecated in favor of the "type" (MIME-type) attribute, and is only included for backwards compatibility.

If a browser is having trouble rendering the menu, it's probably the browser. If it's your composition tool, then it's probably the tool reacting to the DTD as if it mattered to the script.

Perhaps your script writes non-conforming elements, so it's not the script, per se, but what you are doing with it that doesn't meet the spec.

After you're done editing in your composition program, check the syntax in, say Notepad or SimpleText to see the real deal, and adjust as necessary.

(See: http://www.w3c.org/TR/REC-html40/interact/scripts.html section 18.2.1 for the full <script> definition.)

StupidScript
23rd August 2004, 12:21 PM
I have recently been corrected regarding the syntax of the SCRIPT tag and its "defer" attribute.

While my original posting is technically correct, given a strict reading of the W3C standard, it does not meet the XML standard.

There are several discussions going on regarding exactly how to implement this attribute, including whether to use "defer" or "true" as the value of the attribute, however I have come up with yet another interpretation which I'm going to stand by...until further corrections are necessary.

Here is my take on implementing the "defer" attribute in a SCRIPT tag:

<script language="javascript" type="text/javascript" src="site.js" defer>
</script>

The presence of the attribute triggers the deferral. In the W3C spec, there is no value indicated, rather that the "defer" attribute is itself a boolean attribute, and including it as I have, above, sets its value to "true" or "1", while omitting the attribute sets its value to "false" or "0".

IMHO.