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?
"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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With