Re: Why do this? <SCRIPT TYPE="text/javascript"



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.

.



Relevant Pages

  • Re: Attaching functions to events, from external JS files
    ... >pre-existing HTML content using JavaScript DOM Level 1. ... >adding this type of contents doesn't require to write hardcoded HTML ... >that Mozilla doesn't support CSS. ... like they disable script. ...
    (comp.lang.javascript)
  • Re: how to Enable/Disable textbox dynamically
    ... I think that to recommend doing things for the sake of formal correctness alone without saying as much is a mistake, it undermines the credibility of your recommending doing things that are formally correct where doing them or not may make a difference, such your recommendation to correct the structural invalidity in the mark-up by not placing the SCRIPT elements as the first children of the HTML element ). ... Apart from demonstrating the use of a non-existing MIME type for javascript, they specified a TYPE attribute for SCRIPT elements but forgot to mirror it in NOSCRIPT element attributes but the NOSCRIPT content would not be shown either because javascript would be enabled on the browser). ...
    (comp.lang.javascript)
  • Re: Ajax / Javascript Fallback
    ... "Weil es HTML von sich aus kann" ist kein ... die an Javascript gar nicht interessiert sind, ... in jedem Fall immer das gesamte verändernde Script herunterladen. ... Das ist ein Argument. ...
    (de.comp.lang.javascript)
  • Security holes in Hotmail, Yahoo, and other webmails
    ... Most webmails services and applications have huge security holes on the ... execution of malicious javascript and HTML code ... some parts of the user's mailbox, without use of javascript. ... Cross-site scripting vulnerabilities on the yahoo.com domain was reported ...
    (Vuln-Dev)
  • Re: HTML4.01 STRICT and hyperlinks with target
    ... new window *in HTML* instead of in JavaScript. ... have a link open a new window in HTML instead of in JavaScript. ... I know this is not a great reason, but I think it is reason ...
    (comp.infosystems.www.authoring.html)