Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
641 views
in Technique[技术] by (71.8m points)

internet explorer 8 - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

"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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...