Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't IE8 recognize type="application/javascript" in a script tag?

I developed an HTML page that uses jQuery and Ajax. I had the following lines in my <head> tag:

<script language="javascript" type="application/javascript" src="script/jquery.js"></script>
<script language="javascript" type="application/javascript">
    function someFunction() {
        some code;
    }
</script>
    ...

  later - down in the body tag:
<a href="javascript:someFunction();">click here</a>

It worked perfectly in FF and Chrome, but threw an "Object Expected" in IE8 as soon as I clicked the link. Even with the Script Debugger on, it would not reach the first line of the function.
I tried switching to IE7 mode, or IE8 Compatability mode - to no avail.

I lucked out and found a question through Google where someone suggested changing the type in the <script> tag to "text/javascript" and now it works in all 3 browsers.

My question is: what did I do wrong? Is "text/javascript" better than "application/javascript", or is there a better (== more correct) solution to my issue?

like image 443
Traveling Tech Guy Avatar asked Aug 17 '09 14:08

Traveling Tech Guy


2 Answers

"text/javascript" is the only type that is supported by all three browsers. However, you don't actually need to put a type. The type attribute of a script tag will default to "text/javascript" if it is not otherwise specified. How that will affect validation, I'm not sure. But does that really matter anyway?

like image 179
geowa4 Avatar answered Nov 18 '22 03:11

geowa4


Simple answer is that IE doesn't support the type value of application/javascript. The RFC 4329 which recommends it obviously came after the release of IE6, I guess the MS developers didn't feel the need to even support the MIME type.

like image 23
meder omuraliev Avatar answered Nov 18 '22 01:11

meder omuraliev