javascript 如果用户使用 IE8 浏览,则禁用脚本

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

Disable script if user browsing using IE8

javascriptinternet-explorerinternet-explorer-8

提问by johnathan

i want a javascript code to disable the script i made if the user is browsing using Internet explorer 8.

如果用户使用 Internet Explorer 8 浏览,我想要一个 javascript 代码来禁用我制作的脚本。

回答by naveen

Try this.

试试这个。

For disabling script for IE 8

用于禁用 IE 8 的脚本

<!--[if !(IE 8)]><!-->
    <script src="path/to/external/script"></script>
    <script>
        // your inline script goes here
    </script>
<!--<![endif]-->

For disabling script for IE 8 and above

用于禁用 IE 8 及更高版本的脚本

<!--[if !(gte IE 8)]><!-->
    <script src="path/to/external/script"></script>
    <script>
        // your inline script goes here
    </script>
<!--<![endif]-->

Read bobince's answer: Conditional comment for 'Except IE8'?

阅读 bobince 的回答:“除了 IE8”的条件评论?

回答by cdeszaq

One way to do this would be to use another script, enclosed in IE-specific conditional comments, to deactivate the first one. Of course, this means you need to have some way to deactivate the 1st one, but that's not an IE-specific issue.

一种方法是使用包含在 IE 特定条件注释中的另一个脚本来停用第一个脚本。当然,这意味着您需要有某种方法来停用第一个,但这不是特定于 IE 的问题。

Something like this:

像这样的东西:

<!--[if (gte IE 8) ]><script>deactivate1stScript();</script><![endif]-->

By using the conditional comments, you are letting IE do the work, and no other browser will have to process any extra JavaScript because only IE will pay attention to the code in the comments (and IE8 specifically)

通过使用条件注释,您让 IE 来完成工作,其他浏览器将不必处理任何额外的 JavaScript,因为只有 IE 会注意注释中的代码(特别是 IE8)

However, I do agree with @Quentin that targeting specific browsers is usually not the best idea. If there is certain functionality that your script needs, such as Canvasor SVGsupport, using a feature-detection library such as Modernizris a much better way to deal with this.

但是,我同意 @Quentin 的观点,即针对特定浏览器通常不是最好的主意。如果您的脚本需要某些功能,例如CanvasSVG支持,则使用功能检测库(例如Modernizr)是处理此问题的更好方法。

回答by sll

See very straightforward solution here How to detect IE8 using JavaScript

在此处查看非常简单的解决方案如何使用 JavaScript 检测 IE8

The main idea is to run javascript functuion which return version of a current browser and than construct your script usng conditional statements like if, switch

主要思想是运行 javascript functuion,它返回当前浏览器的版本,然后使用条件语句构建脚本,例如 if, switch