jQuery无法检测到IE 11 [英] Jquery fail to detect IE 11

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

问题描述

偶然发现一个问题。尝试使用Jquery检测IE 11(当前正在发布的Beta版本)时,结果为 firefox。相同的代码可以检测IE10。我需要知道用户使用的浏览器才能显示不同的指令。

Just stumbled upon an issue. When trying to detect IE 11 (the beta version currently on air) using Jquery, the result is 'firefox'. The same code detect IE 10. I need to know what browser the user is using in order to display different instructions.

如果有必要,我正在Oracle VirtualBox中进行测试。操作系统是Win 7。

I am testing in Oracle VirtualBox if it matters. The OS is Win 7.

这是代码:

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script>
var browser = function() { 
if ($.browser.msie) return "ie";
var ua = navigator.userAgent.toLowerCase();
if ($.browser.mozilla/* && /firefox/.test(ua)*/) return "firefox"; 
if (/chrome/.test(ua)) return "chrome";
return /*"#"*/'unknown';
} ();

alert (browser); // This return firefox
alert ($.browser.version); // This returns 11.0 - the CORRECT version of IE
</script>

如您所见,Jquery可以找到浏览器版本,但找不到浏览器名称。
您知道如何绕过它吗?

As you can see, Jquery can find the browser version, but not the browser name. Any idea how to bypass it?

推荐答案

最终解决方案:

if (!!navigator.userAgent.match(/Trident\/7\./))
  return "ie";  

我们只能希望发行版本的行为相同。

We can only hope that the release version will act the same.

这篇关于jQuery无法检测到IE 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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