使用 jQuery 在 Internet Explorer 上出现 Javascript 错误,但在 Firefox 上运行良好

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10923239/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 11:29:08  来源:igfitidea点击:

Javascript errors on internet explorer with jQuery but working fine on Firefox

javascriptjquerymagentoprototypejs

提问by user994319

A quick question I'm hoping someone can help me out with.

一个快速的问题,我希望有人可以帮助我。

On firefox our jQuery slider is working perfectly, however on viewing with internet explorer there are some javascript errors occurring. The website is http://foscam-uk.com/index.php

在 Firefox 上,我们的 jQuery 滑块运行良好,但是在使用 Internet Explorer 查看时出现了一些 javascript 错误。该网站是http://foscam-uk.com/index.php

Hoping there is a possible solution to this.

希望有一个可能的解决方案。

Kind Regards and Thank You!

亲切的问候和谢谢!

Errors: Webpage error details

错误:网页错误详情

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3) Timestamp: Wed, 6 Jun 2012 22:36:43 UTC

用户代理:Mozilla/4.0(兼容;MSIE 8.0;Windows NT 6.1;WOW64;Trident/4.0;SLCC2;.NET CLR 2.0.50727;.NET CLR 3.5.30729;.NET CLR 3.0.30729;Media Center PC 60. .NET4.0C;.NET4.0E;InfoPath.3) 时间戳:2012 年 6 月 6 日星期三 22:36:43 UTC

Message: Object doesn't support this property or method Line: 5653 Char: 9 Code: 0 URI: http://foscam-uk.com/js/prototype/prototype.js

消息:对象不支持此属性或方法行:5653 字符:9 代码:0 URI:http: //foscam-uk.com/js/prototype/prototype.js

Message: Object doesn't support this property or method Line: 5988 Char: 5 Code: 0 URI: http://foscam-uk.com/js/prototype/prototype.js

消息:对象不支持此属性或方法行:5988 字符:5 代码:0 URI:http: //foscam-uk.com/js/prototype/prototype.js

Message: Object doesn't support this property or method Line: 2 Char: 5 Code: 0 URI: http://foscam-uk.com/skin/frontend/default/theme316/js/scripts.js

消息:对象不支持此属性或方法行:2 字符:5 代码:0 URI:http: //foscam-uk.com/skin/frontend/default/theme316/js/scripts.js

Message: Object doesn't support this property or method Line: 5736 Char: 7 Code: 0 URI: http://foscam-uk.com/js/prototype/prototype.js

消息:对象不支持此属性或方法行:5736 字符:7 代码:0 URI:http: //foscam-uk.com/js/prototype/prototype.js

Message: Object doesn't support this property or method Line: 5988 Char: 5 Code: 0 URI: http://foscam-uk.com/js/prototype/prototype.js

消息:对象不支持此属性或方法行:5988 字符:5 代码:0 URI:http: //foscam-uk.com/js/prototype/prototype.js

Message: Object doesn't support this property or method Line: 73 Char: 11 Code: 0 URI: http://foscam-uk.com/index.php

消息:对象不支持此属性或方法行:73 字符:11 代码:0 URI:http: //foscam-uk.com/index.php

回答by ertan

IE has some limitations on number of CSS and JS files. (Around 30). I didn't count but seems like you have tons of JS and css file references. If you exceed this IE basically stop downloading the script or css file. You can verify it yourself by using Fiddler.

IE 对 CSS 和 JS 文件的数量有一些限制。(大约 30 个)。我没有计算,但似乎你有大量的 JS 和 css 文件引用。如果超过这个IE基本停止下载脚本或css文件。您可以使用 Fiddler 自行验证。

Try to compact them to single file with compressor tools (ex: http://developer.yahoo.com/yui/compressor/)

尝试使用压缩器工具将它们压缩为单个文件(例如:http: //developer.yahoo.com/yui/compressor/

回答by artlung

So it looks like you're loading a several third party libraries. You're loading PrototypeJS, Scriptaculous, jQuery, and jQuery plugins*. It appears to me what you have is not so much a JavaScript problem as a plugin organization problem.

所以看起来你正在加载几个第三方库。您正在加载 PrototypeJS、Scriptaculous、jQuery 和 jQuery 插件*。在我看来,您所拥有的与其说是 JavaScript 问题,不如说是插件组织问题。

Now, you do appear to be using things like jQuery.noConflict()in one place, but then not in another.

现在,您似乎确实jQuery.noConflict()在一个地方使用了一些东西,但在另一个地方却没有。

My suggestion is to deactivate all the current modules you're using on the site which inject JavaScript, and then re-enable them one at a time. Each time you re-enable a plugin, check to see whether that, and all the other plugins are also working.

我的建议是停用您在站点上使用的所有当前模块,这些模块会注入 JavaScript,然后一次重新启用它们。每次重新启用插件时,请检查它是否以及所有其他插件是否也能正常工作。



*Actually, you're loading more than just a few libraries. You're actually loading two versions of jQuery, plus Prototype. This is not a good practice. Here's what I can see, not counting the Magento generated code that is being inserted:

*实际上,您加载的不仅仅是几个库。您实际上正在加载jQuery 的两个版本,以及 Prototype。这不是一个好的做法。这是我所看到的,不包括正在插入的 Magento 生成的代码:

  • Prototype 1.7
  • Credit Card Validation Javascript
  • Really easy field validation with Prototype
  • script.aculo.us builder.js
  • script.aculo.us effects.js
  • script.aculo.us controls.js
  • script.aculo.us slider.js
  • jQuery 1.4.2
  • jCarouselLite
  • jQuery 1.7.1
  • TMSlider: jQuery based image slider
  • jQuery Easing v1.3
  • 原型 1.7
  • 信用卡验证 Javascript
  • 使用 Prototype 进行非常简单的字段验证
  • script.aculo.us builder.js
  • script.aculo.us effects.js
  • script.aculo.us control.js
  • script.aculo.us slider.js
  • jQuery 1.4.2
  • jCarouselLite
  • jQuery 1.7.1
  • TMSlider:基于 jQuery 的图像滑块
  • jQuery 缓动 v1.3

You need to do a rethink as to how you're handling some of these effects. There's a great deal of overlap in what these libs do, and you'd be better off seeing if there's a way to create some sanity in which modules you're choosing.

您需要重新考虑如何处理其中一些影响。这些库的功能有很多重叠,你最好看看是否有办法在你选择的模块中创建一些理智。

回答by BumbleB2na

prototype.js seems to be throwing errors in every browser but these seem to have no effect on your site.

prototype.js 似乎在每个浏览器中都会抛出错误,但这些似乎对您的网站没有影响。

your site works fine in IE7 and IE10. In IE8, your version of jQuery throws an error, not the slider code. I would upgrade your 1.7.1 version of jQuery to 1.7.2 (the latest).

您的网站在 IE7 和 IE10 中运行良好。在 IE8 中,您的 jQuery 版本会引发错误,而不是滑块代码。我会将您的 jQuery 1.7.1 版本升级到 1.7.2(最新版本)。

回答by DFBerry

I had a similar issue with my client-side script. The IE10 F12 Dev tools script tab showed errors on jQuery syntax even though the site worked in IE8 and IE9.

我的客户端脚本也有类似的问题。即使该站点在 IE8 和 IE9 中运行,IE10 F12 开发工具脚本选项卡也会显示 jQuery 语法错误。

One of the libraries I used (Telerik Kendo UI) was not IE10 compatible yet.

我使用的库之一(Telerik Kendo UI)尚不兼容 IE10。

In order to force IE10 to show the page, I had to add this meta tag to the very top (first item in head) of my HEAD tag:

为了强制 IE10 显示页面,我必须将此元标记添加到我的 HEAD 标记的最顶部(头部的第一项):

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

Then the pages worked again.

然后页面再次工作。