jQuery issue in Internet Explorer 8

2020-01-24 10:43发布

I am trying to get my jQuery functions to work on IE8. I am loading the library from Google's servers (http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js).

The $(function(){}) is never called. Instead, I get an error Object expected. I opened the developer and ran typeof $ in the console, and it came up as undefined.

I have tried going to other sites that I know use jQuery (jquery.com), and those all work, is there something I might be missing here?

20条回答
老娘就宠你
2楼-- · 2020-01-24 11:10

In short, it's because of the IE8 parsing engine.

Guess why Microsoft has trouble working with the new HTML5 tags (like "section") too? It's because MS decided that they will not use regular XML parsing, like the rest of the world. Yes, that's right - they did a ton of propaganda on XML but in the end, they fall back on a "stupid" parsing engine looking for "known tags" and messing stuff up when something new comes around.

Same goes for IE8 and the jquery issue with "load", "get" and "post". Again, Microsoft decided to "walk their own path" with version 8. Hoping that they solve(d) this in IE9, the only current option is to fall back on IE7 parsing with <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />.

Oh well... what a surprise that Microsoft made us post stuff on forums again. ;)

查看更多
何必那么认真
3楼-- · 2020-01-24 11:12

I had this problem and tried the solutions mentioned here with no success.

Eventually, I realised that I was linking to the Google CDN version of the script using an http URL while the page embedding the script was an https page.

This caused IE to not load jquery (it prompts the user whether they want to load only secure content). Changing the Google CDN URL to use the https scheme fixed the problem for me.

查看更多
虎瘦雄心在
4楼-- · 2020-01-24 11:12

I think that you have same problem as I do:

Message: Permission denied
Line: 13
Char: 27021
Code: 0
URI: http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.3.2.min.js

Because of cross domain reference. Try to host jquery.js on same domain.

查看更多
姐就是有狂的资本
5楼-- · 2020-01-24 11:13

Maybe you have inPrivate Filtering turned on?

查看更多
太酷不给撩
6楼-- · 2020-01-24 11:14

The error Object expected is raised because Jquery is not loaded. This happens because of browser security (usually IE) which does not allow you executing external javascript source code. You can correct this problem by:

  • 1: Changing browser security level to allow executing external javascript code. You can find how to do this here

OR

  • 2: Copy-paste the jquery source code into your web page so that it won't be considered as an external script.

I prefer the first solution.

查看更多
成全新的幸福
7楼-- · 2020-01-24 11:20

Maybe you insert two scripts,it should be work.

<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE8.js"></script>  
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js">/script> 
查看更多
登录 后发表回答