简体   繁体   English

Internet Explorer 8中的jQuery问题

[英]jQuery issue in Internet Explorer 8

I am trying to get my jQuery functions to work on IE8. 我试图让我的jQuery函数在IE8上工作。 I am loading the library from Google's servers ( http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js ). 我正在从Google的服务器加载库( http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js )。

The $(function(){}) is never called. 永远不会调用$(function(){}) Instead, I get an error Object expected . 相反,我得到一个Object expected的错误Object expected I opened the developer and ran typeof $ in the console, and it came up as undefined . 我打开了开发人员并在控制台中运行了typeof $ ,它出现了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? 我试过去其他我知道使用jQuery(jquery.com)的网站,那些都有用,有什么我可能会在这里缺少的吗?

Write "var" before variables, when you define them. 在定义变量之前,在变量之前写下“var”。 IE8 dies when there is no "var". IE8在没有“var”时死亡。

Correction: 更正:

Check your script include tag, is it using 检查您的脚本包含标记,是否正在使用

type="application/javascript" src="/path/to/jquery" 

change to 改成

type="text/javascript" src="/path/to/jquery" 

I was having a similar issue. 我遇到了类似的问题。 Things worked in IE6, Firefox, and IE8 running in IE7 compatibility mode; 在IE7,Firefox和IE8中运行的东西在IE7兼容模式下运行; but not in 'normal' IE8. 但不是'正常'的IE8。 My solution was to put this code in the header 我的解决方案是将此代码放在标题中

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> 

As to why jquery isn't working in IE8 I'm unclear. 至于为什么jquery不能在IE8中工作,我不清楚。

The solution is to upgrade to the latest version of jQuery. 解决方案是升级到最新版本的jQuery。 I had the exact same problem and upgraded to 1.4.2 and it all works fine again in IE8. 我有完全相同的问题,并升级到1.4.2,它在IE8中再次正常工作。

Seems to be totally backwards-compatible with all the jQuery 1.3.2 stuff I did as well so no complaints here! 似乎完全向后兼容我所做的所有jQuery 1.3.2的东西,所以没有投诉!

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 . 最后,我意识到我使用http URL链接到脚本的Google CDN版本,而嵌入脚本的页面是https page

This caused IE to not load jquery (it prompts the user whether they want to load only secure content). 这导致IE无法加载jquery(它会提示用户是否只想加载安全内容)。 Changing the Google CDN URL to use the https scheme fixed the problem for me. 更改Google CDN URL以使用https方案为我解决了问题。

Some people stumbling on this post might get this issue with jquery and IE8 because they're using >= jQuery v2. 有些人在这篇文章上磕磕绊绊可能会在jquery和IE8中遇到这个问题,因为他们正在使用> = jQuery v2。 Use this code: 使用此代码:

<!--[if lt IE 9]>
    <script src="jquery-1.9.0.js"></script>
<![endif]-->
<!--[if gte IE 9]><!-->
    <script src="jquery-2.0.0.js"></script>
<!--<![endif]-->

If you are using HTTPS on your site, you will need to load the jQuery library from Googles https server instead. 如果您在站点上使用HTTPS,则需要从Googles https服务器加载jQuery库。 Try this: https://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js (or the latest https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js ) 试试这个: https//ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js (或最新的https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/ jquery.min.js

jQuery is not being loaded, this is not likely specific to IE8. jQuery没有加载,这可能不是特定于IE8。 Check the path on your jQuery include. 检查jQuery包含的路径。 statement. 声明。 Or better yet, use the following to the CDN: 或者更好的是,将以下内容用于CDN:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js">
</script>

I was fixing a template created by somebody else who forgot to include the doctype. 我被固定由其他谁忘了,包括文档类型创建的模板。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

If you don't declare the doctype IE8 does strange things in Quirks mode. 如果你没有声明doctype IE8在Quirks模式下做了奇怪的事情。

The onload event does not always work on IE7/8 in <head> ... </head> onload事件并不总是在<head> ... </head> IE7 / 8上工作

You can force it by adding an onload script at the end of your page before the tag as below. 您可以通过在标记之前的页面末尾添加onload脚本来强制它,如下所示。

  <script>
    window.onload();
  </script>
</body>

The error Object expected is raised because Jquery is not loaded. 由于未加载Jquery,因此引发了Object expected的错误Object expected This happens because of browser security (usually IE) which does not allow you executing external javascript source code. 这是因为浏览器安全(通常是IE),它不允许您执行外部JavaScript源代码。 You can correct this problem by: 您可以通过以下方式更正此问题

OR 要么

  • 2: Copy-paste the jquery source code into your web page so that it won't be considered as an external script. 2:将jquery源代码复制粘贴到您的网页中,这样就不会将其视为外部脚本。

I prefer the first solution. 我更喜欢第一种解决方案。

I had the same problems. 我遇到了同样的问题。

I solved it verifying that IE8 was not configured correctly to reach the SRC URL. 我解决了它验证IE8没有正确配置到达SRC URL。

I changed this, it works right. 我改变了这个,它运作正常。

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> 

This fixed my issue in IE8: 这解决了我在IE8中的问题:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>

Running on localhost, I had to change the https:// to http:// 在localhost上运行,我不得不将https://更改为http://

If I try to browse to the secure link, I get the Internet Explorer cannot display the webpage friendly warning. 如果我尝试浏览到安全链接,我得到的Internet Explorer无法显示网页友好警告。

Always try to load your text scripts in a browswer first if there are issues! 如果有问题,请务必先在浏览器中加载文本脚本!

I had the same issue. 我遇到过同样的问题。 The solution was to add the link to the JQuery file as a trusted site in IE. 解决方案是将链接添加到JQuery文件中作为IE中的可信站点。

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. 尝试在同一个域上托管jquery.js。

也许你已经开启了私人过滤

The solution in my case was to take any special characters out of the URL you're trying to access. 在我的情况下,解决方案是从您尝试访问的URL中取出任何特殊字符。 I had a tilde (~) and a percentage symbol in there, and the $.get() call failed silently. 我有一个波浪号(〜)和一个百分比符号,$ .get()调用无声地失败。

OK! 好! I know that jQuery is loading. 我知道jQuery正在加载。 I know that jQuery.textshadow.js is loading. 我知道jQuery.textshadow.js正在加载。 I can find both of the scripts in Developer Tools. 我可以在Developer Tools中找到这两个脚本。

The weird part: this code is working in the content area but not in the banner. 奇怪的部分:此代码在内容区域中工作,但不在横幅中。 Even with a dedicated fixIE.css . 即使有专门的fixIE.css AND it works when I put the css inline. 并且当我把css内联时它工作。 (That, of course, messes up FireFox.) (那当然会弄乱FireFox。)

I have even put in a conditional IE span around the text field in the banner with no luck. 我甚至在横幅中的文本字段中放入了条件IE浏览器,没有运气。

I found no difference and had the same errors in both jquery-1.4.2.min.js and jquery-1.2.6.min.js . 我发现没有区别,并且在jquery-1.4.2.min.jsjquery-1.2.6.min.js中都有相同的错误。 jquery.textshadow.js was downloaded from the jQuery site while trying to find a solution to this problem. jquery.textshadow.js是从jQuery网站下载的,同时试图找到这个问题的解决方案。

This is not posted to the Website 这不会发布到网站上

In short, it's because of the IE8 parsing engine. 简而言之,这是因为IE8解析引擎。

Guess why Microsoft has trouble working with the new HTML5 tags (like "section") too? 猜猜为什么微软也难以使用新的HTML5标签(如“部分”)? It's because MS decided that they will not use regular XML parsing, like the rest of the world. 这是因为MS决定他们不会像世界其他地方那样使用常规的XML解析。 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. 是的,这是对的 - 他们对XML进行了大量的宣传,但最终,他们又回到了一个“愚蠢”的解析引擎,寻找“已知标签”并在出现新事物时弄乱了东西。

Same goes for IE8 and the jquery issue with "load", "get" and "post". IE8和jquery问题同样适用于“load”,“get”和“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" /> . 再次,微软决定用版本8“走自己的路”。希望他们在IE9中解决这个问题,唯一的当前选择是使用<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />回归IE7解析<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />

Oh well... what a surprise that Microsoft made us post stuff on forums again. 哦......好吧,微软让我们再次在论坛上发布了一些内容。 ;) ;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM