javascript DOMParser 在 IE9 中未定义

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

DOMParser is undefined in IE9

javascriptinternet-explorerinternet-explorer-9

提问by mihsathe

I am getting a very weird kind of error with IE9. When I use a DOMParser from within a jsp page on localhost, it runs perfectly fine and gives the proper result.

我在使用 IE9 时遇到了一种非常奇怪的错误。当我从本地主机上的 jsp 页面中使用 DOMParser 时,它运行得非常好并给出了正确的结果。

But Shockingly, when I use DOMParser inside a normal HTML file (Not on the server. From the file system), I get this annoying message of "DOMParser is undefined" .. What is this and how can I make it work? Thank You.

但令人震惊的是,当我在普通 HTML 文件(不在服务器上。从文件系统)中使用 DOMParser 时,我收到了“DOMParser 未定义”的烦人消息..这是什么以及如何使其工作?谢谢。

P.S. It works fine on FF and Chrome

PS 它在 FF 和 Chrome 上运行良好

回答by Spudley

I would say that this is almost certain to be the browser running in compatibility mode when browsing local URLs.

我会说这几乎可以肯定是浏览器在浏览本地 URL 时以兼容模式运行。

You can check this by opening the dev tools (press F12) and looking in the top right corner; if it says it's in IE7 mode, then you've found the problem. Switch it back to normal IE9 mode and it should come right.

您可以通过打开开发工具(按 F12)并查看右上角来检查这一点;如果它说它处于 IE7 模式,那么你已经找到了问题。将其切换回正常的 IE9 模式,它应该会正确。

IE7 didn't support the DomParser object, so if IE9 is in IE7 compatibility mode, it's natural that it will stop supporting it too.

IE7 不支持 DomParser 对象,所以如果 IE9 处于 IE7 兼容模式,它自然也会停止支持它。

Ok, so that's what it's doing. But why is it doing this? There is a config setting in IE (both IE8 and IE9) which specifies that the browser should fall into compatibility mode when browsing sites on the local intranet. The reason for this setting existing is to allow companies who have internal sites designed for older versions of IE to upgrade to a new version without breaking those sites. It's intended to make like easier for corporate types who would rather not spend money fixing something when the broken version is good enough.

好的,这就是它正在做的。但它为什么要这样做呢?IE(IE8 和 IE9)中有一个配置设置,它指定浏览器在本地 Intranet 上浏览站点时应进入兼容模式。存在此设置的原因是允许拥有为旧版本 IE 设计的内部站点的公司升级到新版本而不会破坏这些站点。它旨在让企业类型更容易,他们宁愿在损坏的版本足够好时不花钱修复某些东西。

But it's a pain in the rear for the rest of us.

但这对我们其他人来说是一种痛苦。

Obviously, if your site is on the public internet, it won't be affected by this flag, except when you're trying to work on it from localhost on your own PC. Therefore, the solution for you is to simply turn off this config setting in the browser and forget about it.

显然,如果您的站点位于公共 Internet 上,则它不会受到此标志的影响,除非您尝试在自己的 PC 上从 localhost 处理它。因此,您的解决方案是简单地在浏览器中关闭此配置设置并忘记它。

Of course, the fact remains that users of IE7 will still have this problem with your site, as their browser doesn't support the feature you're using. You could just drop support for IE7, and tell those users to upgrade. But if you want to support IE7 users, I believe that Dean Edwards' IE7.jsscript allows the browser to emulate this feature (along with a bunch of other stuff that Microsoft forgot).

当然,事实上 IE7 的用户仍然会在您的网站上遇到这个问题,因为他们的浏览器不支持您正在使用的功能。您可以放弃对 IE7 的支持,并告诉这些用户升级。但是如果你想支持 IE7 用户,我相信 Dean Edwards 的IE7.js脚本允许浏览器模拟这个功能(以及微软忘记的一堆其他东西)。

Hope that helps.

希望有帮助。

回答by user2320952

I received this error, "DOMParser is undefined", on IE9 and it turned out to be an add-on that was disabled.

我在 IE9 上收到此错误“DOMParser 未定义”,结果证明它是一个已禁用的附加组件。

Name XML DOM Document Publisher Microsoft Corporation Status Enabled

名称 XML DOM Document Publisher Microsoft Corporation Status Enabled

Tools – Manage Add-ons – Microsoft Corporation

工具 – 管理加载项 – Microsoft Corporation