Forum Moderators: open

Message Too Old, No Replies

What's the difference between type="text/javascript" and type="javascript"?

         

java_junkie

5:55 pm on Jun 17, 2007 (gmt 0)

10+ Year Member



what's the difference between:
<script type="text/javascript"> and <script type="javascript">

colandy

5:58 pm on Jun 17, 2007 (gmt 0)

10+ Year Member



One has the word 'text' in it

lol

java_junkie

6:04 pm on Jun 17, 2007 (gmt 0)

10+ Year Member



I have been running a script with <script type="text/javascript"> and it's functioning when I tried using <script type="javascript"> it isn't running that's why i asked lol

colandy

7:59 am on Jun 18, 2007 (gmt 0)

10+ Year Member



OK, the difference is that one works and the other doesn't.

I've never seen the statement:

<script type="javascript">

before, only ever with the 'text' wording included. I think it's just a case of that's what the browser expects to see.

encyclo

9:49 am on Jun 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It will work if you use
<script>
, as Javascript is the default scripting language. However the HTML specification requires that you define the mime type of the script.

You have two versions, the older

language="Javascript"
(only required for very old browsers), and the more usual
type="text/javascript"
. The latter is required to pass validation.

Bernard Marx

11:11 am on Jun 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I consider Douglas Crockford to be a good candidate for an "authority" on Javascript. Check out his video, "Theory of The DOM" (Pt 1) [video.yahoo.com] at Yahoo video. 16 minutes in, he talks about this issue.

The gist is that, in fact, we might as well leave out the type attribute entirely for the time being, since "text/javascript" is non-standard.

[edited by: Bernard_Marx at 11:12 am (utc) on June 18, 2007]