0

According to this:

http://www.w3.org/TR/1999/REC-html401-19991224/interact/scripts.html

The type of script my be added in the script tag. Some values are: "text/tcl", "text/javascript", "text/vbscript".

Recently I've seen in this page: Cofeescript in 1,2,3 the following:

 <script src="coffee-script.js"></script>
 <script type="text/coffeescript">
         alert "Hello CoffeeScript!"
 </script>

And works great! ( I had to download the cofeescript library and use the one in the extra folder )

My question is. How does the browser knows that a given script should be handled? I have no idea.

mykhal
  • 19,175
  • 11
  • 72
  • 80
OscarRyz
  • 196,001
  • 113
  • 385
  • 569

4 Answers4

1

Seeing as you can't finish your answer, it's not yet entirely clear what your question is ;)

But the answer to this question is related: The type attribute of SCRIPT and STYLE elements in HTML?

Summary:

  • type is indeed a required attribute in HTML 4

  • it defaults to text/javascript in HTML 5

as far as I know, text/javascript is the de facto default in all modern browsers if the property is missing even in HTML 4.

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
1

Since HTML5, the type attribute is optional (it is required in HTML4 though) and the default value is text/javascript.

Harmen
  • 22,092
  • 4
  • 54
  • 76
0

The browser simply recognises some specific types of script, and ignores everything else.

Internet Explorer for example recognises the type "text/javascript" and runs the script, eventhough it actually runs it as JScript.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
0

I believe that the default in browsers is to interpret a script tag as holding JavaScript; whilst the spec that you've listed indicates that there is no default value for the type attribute, that doesn't mean that browsers won't provide their own default.

Russ Cam
  • 124,184
  • 33
  • 204
  • 266