javascript 网站可在 Firefox 和 Chrome 中运行,但不能在 Internet Explorer 中运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4906823/
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-25 15:19:23  来源:igfitidea点击:

Site works in Firefox and Chrome but not Internet Explorer

javascriptinternet-explorerobject

提问by Nigel

Apologies but this is not a programming question, but it may have a programming answer.

抱歉,但这不是编程问题,但它可能有编程答案。

For some reason my site, http://pctools.alwinsights.comwill not display properly in IE (I'm using version 8) but it's fine in firefox and chrome. The content does not appear in the centre of the screen in IE and also generates two JS error messages while the pages are loading.

出于某种原因,我的网站http://pctools.alwinsights.com将无法在 IE 中正确显示(我使用的是版本 8),但在 Firefox 和 chrome 中可以正常显示。内容在 IE 中不会出现在屏幕中央,并且在页面加载时也会生成两个 JS 错误消息。

I've tried enabling Active X and Scripts in the security settings but with no joy. I've also looked around the net but cannot find an answer, well not one that works!

我试过在安全设置中启用 Active X 和脚本,但没有任何乐趣。我也环顾了网络,但找不到答案,而且没有一个有效的答案!

Unfortunately I know nothing about javascript so really don't know where to start with the error messages that are generated.

不幸的是,我对 javascript 一无所知,所以真的不知道从生成的错误消息开始。

Any help appreciated.

任何帮助表示赞赏。

regards

问候

Nigel

奈杰尔

Update:

更新:

OK initial error has gone, I'd screwed up with a directory name - apologies.

好的,初始错误消失了,我搞砸了目录名称 - 抱歉。

I've found out that if I disable the option to display the last twitter feed in the wordpress theme it loads OK. So it is the JS code in a php script called thememx-document.js that is causing the error. The code generating the error is "var twitterHtml = jQuery.cookie(twitterCookieName);" It says it's charcater 4, which is a space but I don't understand this.

我发现如果我禁用在 wordpress 主题中显示最后一个 twitter 提要的选项,它加载正常。因此,导致错误的是名为 theemx-document.js 的 php 脚本中的 JS 代码。产生错误的代码是“var twitterHtml = jQuery.cookie(twitterCookieName);” 它说它是字符 4,这是一个空格,但我不明白这一点。

I can live without Twitter on this site but it still leaves issues as to why content isn't centred nor the pop-up ad is not showing (compare to Firefox) but this may not be a programming issue that warrants a question on this site.

我可以在这个网站上没有 Twitter 的情况下生活,但它仍然留下问题,为什么内容不居中或弹出广告没有显示(与 Firefox 相比),但这可能不是一个编程问题,需要在这个网站上提出问题.

Thanks to all for your comments and input.

感谢大家的意见和投入。

Nigel

奈杰尔

回答by Quentin

Start with valid code; a validator will pick up lots of problems. Among yours is content before the Doctype, which triggers quirks mode. Quirks mode causes browsers to emulate bugs in ancient browsers and become much more inconsistent with each other. One of the emulated bugs in Internet Explorer breaks standard centring techniques.

有效代码开始验证器会遇到很多问题。其中包括 Doctype 之前的内容,它会触发 quirks 模式。怪癖模式导致浏览器模仿古代浏览器中的错误,并变得更加不一致。Internet Explorer 中的模拟错误之一破坏了标准的居中技术。

回答by annu balti

for not properly disply-- its the problem of CSS ...IE7 and IE8 dosen't support css3.so you should simply make another css stylesheet for IE and call it on page only if someone visit your site using IE. and for other broswers it will show exiting style.

因为没有正确显示——它的 CSS 问题......IE7 和 IE8 不支持 css3.so 你应该简单地为 IE 制作另一个 css 样式表,并且只有当有人使用 IE 访问你的网站时才在页面上调用它。对于其他浏览器,它将显示退出风格。

and abot JS error --you should check all your php coding and then fix it. its not JS problem. if you are not familar with PHP coding then i am here to offer my free service to you or anyone else. i will help you as i can.

和 abot JS 错误——你应该检查你所有的 php 编码,然后修复它。它不是JS问题。如果您不熟悉 PHP 编码,那么我在这里为您或其他任何人提供免费服务。我会尽力帮助你。

回答by Malvolio

Good.

好的。

OK, maybe your site hasto work for IE. 9 times out of 10, the problem is a terminal comma. The following is understood in real browsers but generates an unintelligible error in IE:

好的,也许您的网站必须适用于 IE。10 次中有 9 次,问题是终端逗号。以下在真实浏览器中可以理解,但在 IE 中会产生无法理解的错误:

var x = [ 1, 2, 3, ];

The tenth time (in my experience), it's string indexing.

第十次(根据我的经验)是字符串索引。

var x = "abc";
var c = x[2];

In a real browser, cis set to "c"; in IE, another unhelpful error message.

在真实浏览器中,c设置为“c”;在 IE 中,另一个无用的错误消息。

If this helps, remember: in IE, it's very important to create as many circular dependencies as possible. That is, attach to DOM elements JavaScript functions that have references to other DOM elements. IE fails to clean up such dependencies when the user leaves your site and so leaks memory. Once it leaks enough memory, IE slows and eventually freezes the OS and the user learns a valuable lesson: don't use IE. (Microsoft has a good pageexplaining how to do this although, inexplicably, they recommend againstdoing it.)

如果这有帮助,请记住:在 IE 中,创建尽可能多的循环依赖关系非常重要。也就是说,将引用其他 DOM 元素的 JavaScript 函数附加到 DOM 元素。当用户离开您的站点时,IE 无法清除此类依赖项,从而导致内存泄漏。一旦它泄漏了足够的内存,IE 就会变慢并最终冻结操作系统,并且用户会学到一个宝贵的教训:不要使用 IE。(微软有一个很好的页面解释了如何做到这一点,但莫名其妙地,他们建议要这样做。)

回答by Rob

First, having problems with any version of IE is expected and the norm. IE is the worst browser on the planet.

首先,任何版本的 IE 都会出现问题,这也是常态。IE 是这个星球上最糟糕的浏览器。

You have a link element on your first line. Links belong inside the head element. Placing it on the first line throws IE into 'quirks mode' and then IE becomes even worse than it normally is.

您的第一行有一个链接元素。链接属于头部元素。将它放在第一行会使 IE 进入“怪癖模式”,然后 IE 变得比平时更糟。