如何检测IE 11在Asp.net的JavaScript [英] How to detect IE 11 with javascript in Asp.net

查看:141
本文介绍了如何检测IE 11在Asp.net的JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想检测浏览器,IE 8或以上将是适合我。为此,我使用以下code,但它没有为IE 11。对于其他的正确检测。

Hello I want to detect the Browser , IE 8 or more will be appropriate for me. For this i used following code but it fails for IE 11 . For other its detecting properly.

function getInternetExplorerVersion()
{
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}

下面是这也是我试过,但不能得逞的链接。

Below is the link which also I tried but couldn't succeed.

推荐答案

DO NOT DO检测浏览器!这将打破,这将导致你的问题。

DO NOT DO BROWSER DETECTION! It will break, and it will cause you problems.

IE11有着完全不同的用户代理字符串以previous的IE版本;它不再包含MSIE的文字。这就是为什么你的检测code不起作用。

IE11 has a completely different User Agent string to previous IE versions; it not longer includes the "MSIE" text. This is why your detection code doesn't work.

在这里指出,他们这样做的原因是故意这一点很重要。他们的希望的突破浏览器检测脚本是这样的。

It's important to note here that the reason they did this was deliberate. They wanted to break browser detection scripts like this.

有可能改变你的code与IE11的工作,但我强烈建议不这样做,因为你可能有同样的问题一遍,当IE12出来。

It is possible to change your code to work with IE11, but I strongly recommend not doing this, as you'll probably have the same issue all over again when IE12 comes out.

那么,为什么他们要打破浏览器检测脚本?简单:因为IE11没有previous版本的错误,而且它有很多新的特性。所以,如果你正在做的浏览器检测因为IE具有一定的漏洞和缺失的功能,你已经有了code来解决基于浏览器的这些问题检测,那么code实际上可能导致IE11更严重的问题在哪里不需要修复。

So why did they want to break browser detection scripts? Simple: Because IE11 does not have the bugs of previous versions, and it has a lot of new features. So if you're doing browser detection because IE has certain bugs or missing features and you've got code to fix those issues based on the browser detect, then that code might actually cause worse problems in IE11 where the fixes aren't needed.

IE11已经打破了你的脚本,但同样的逻辑适用于所有浏览器和所有版本;检测浏览器和版本几乎总是错的事情。

IE11 has broken your script, but the same logic applies to all browsers and all versions; detecting the browser and version is almost always the wrong thing to do.

如果有要支持特定的功能,但在旧的版本的IE(或其他旧的浏览器)丢失,请不要使用浏览器检测去解决它;你应该使用特征检测代替。

If there are specific features that you want to support, but are missing in older IE versions (or other older browsers), don't use browser detection to work it out; you should use feature detection instead.

功能检测手段检查浏览器,看它是否支持您要使用的特定功能。这样做的最常见的方法是使用 Modernizr的的库。在其网站上的文档将指导您完成设置它。

Feature detection means checking the browser to see whether it supports the particular features you want to use. The most common way of doing this is to use the Modernizr library. The docs on their site will guide you through setting it up.

有中老年版本的IE一些错误这是防不胜防,并​​为这些少数情况下,它是有效使用浏览器检测作为最后的手段,但这种情况下,实际上只对IE6及更早版本。也许偶尔IE7。但是你在,你只会看到IE8和后来的问题指出,这样不应适用。

There are a few bugs in older IE versions which are hard to detect, and for these few cases, it is valid to use browser detection as a last resort, but these cases are really only for IE6 and earlier. Maybe occasionally for IE7. But you've stated in the question that you're only looking at IE8 and later, so that should not apply.

坚持使用功能检测;它更可靠,更好的做法,当一个新的浏览器版本发布也不会突然断裂。

Stick with feature detection; it's more reliable, better practice, and won't break suddenly when a new browser version is released.

这篇关于如何检测IE 11在Asp.net的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆