Re: Why do this? <SCRIPT TYPE="text/javascript"
- From: "Richard Cornford" <Richard@xxxxxxxxxxxxxxxxxxx>
- Date: Tue, 6 May 2008 22:41:42 +0100
Steve wrote:
I've being going through some legacy code on an old JSP
site I have been patching. I noticed that when I save
the JSP down to my PC as an HTML file I get this
javascript error in IE 6 ( not in the latest
Firefox ):
"invalid character"
The problem traces back to this line of code:
<SCRIPT TYPE="text/javascript" SRC="abc/jsp/blah.js"></SCRIPT>
That error usually means that the SRC's URL does not refer to an existing resource, and the resulting 404 error page is HTML which when interpreted as javascript source code will produce one form of syntax error or another.
It goes away if I remove the "text/".
Yes, you have then prevented the browser from recognising the type of script and so it is not passing it into its javascript interpreter and so not finding the HTML that it is receiving erroneous when interpreted as javascript.
I have never seen a script tag with "TYPE" or "text/javascript"
used.
Then you had best leave web development to someone with a little more relevant experience.
Only "language = "javascript""
The language attribute of SCRIPT elements is deprecated in HTML 4 and not usable with strict (x)HTML DTDs.
What is <SCRIPT TYPE="text/javascript" used for?
The type attribute is required in valid HTML and is used to declare the type of script language used.
Is it necessary?
For valid mark-up it is required, in a purely practical sense it is not necessary. Most browsers will default to assuming javascript is the type of script language to use unless told something else, and most browsers can cope with defective/non-valid (a.k.a. 'tag soup') HTML mark-up to some degree or another. On the other hand, using mark-up that it at minimum structurally valid can avoid issues when attempting to script the resulting DOM, and having formally valid mark-up is one way of guaranteeing that the mark-up is structurally valid.
Richard.
.
- References:
- Why do this? <SCRIPT TYPE="text/javascript"
- From: Steve
- Why do this? <SCRIPT TYPE="text/javascript"
- Prev by Date: Re: JavaScript A* Path Finding Prototype
- Next by Date: Re: Why do this? <SCRIPT TYPE="text/javascript"
- Previous by thread: Why do this? <SCRIPT TYPE="text/javascript"
- Next by thread: Re: Why do this? <SCRIPT TYPE="text/javascript"
- Index(es):
Relevant Pages
|