如何使用javascript检测IE10? [英] How do I detect IE10 using javascript?

查看:108
本文介绍了如何使用javascript检测IE10?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于许多已经在其他问题(也在jQuery文档中)上发布,旧的 jQuery.browser.version 已被弃用,只能在jquery1.3中使用。

As many already posted in other questions (also in jQuery documentation), the old jQuery.browser.version is deprecated and works only in jquery1.3.

你知道另一个简单的方法来检测它,我可以包含在我的代码之前:

Do you know another simple way to detect it, that I can include in my code before:

function handleInfoDivPopupVisibility(dynamicEleId, staticEleId){
var parentContainer = $('headerSummaryContainer');
var dynamicEle = $(dynamicEleId);
var staticEle = $(staticEleId);

if(isIE() && parentContainer){
    if (jQuery.browser.version != 10) { // I need to find a way to detect if it's IE10 here.
        parentContainer.style.overflow = 'visible'; 
    }
}
dynamicEle ? dynamicEle.style.display = '' : '';
if(dynamicEle && staticEle)
    gui_positionBelow(dynamicEle, staticEle);
}

在你说它的重复问题 this ,我想强调,我不想使用css hacks。有没有办法检测它,就像以前一样简单?

Before you say it's duplicated question of this or this, I'd like to reinforce that I don't want to use css hacks. Is there a way to detect it just as simple as I could do before?

if (jQuery.browser.version != 10) {...


推荐答案

它是一个坏主意,检查浏览器版本,它被认为是更好的做法,检查浏览器功能。但如果你确定你在做什么:

In general it's a bad idea to check for browser version, it's considered a better practice to check for browser features. But if you're sure what you're doing:

function getIEVersion(){
    var agent = navigator.userAgent;
    var reg = /MSIE\s?(\d+)(?:\.(\d+))?/i;
    var matches = agent.match(reg);
    if (matches != null) {
        return { major: matches[1], minor: matches[2] };
    }
    return { major: "-1", minor: "-1" };
}

var ie_version =  getIEVersion();
var is_ie10 = ie_version.major == 10;

我们在生产中有以下代码,所以它工作正常并经过良好测试。

We have the following code in production, so it works and well-tested.

是的,我们确实需要检测IE10,而不仅仅是IE10中存在的特殊功能,而不是早期版本。

And yes, we did have a need to detect IE10, not just a particular feature that exists in IE10 but not in earlier versions.

这篇关于如何使用javascript检测IE10?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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