javascript IE 11 浏览器将自己识别为 Mozilla
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20911175/
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
IE 11 browser recognizes itself as Mozilla
提问by BumbleBee
I am working on MVC application, .net 4.5 framework, VS 2010. I have a piece of Javascript code that identifies which browser the application is running. If the browser is Firefox then a particular block of code will be executed if not another block code will get executed. With IE 11 I am having a weird problem. The browser (ie 11) recognizes itself as Mozilla.
我正在开发 MVC 应用程序、.net 4.5 框架、VS 2010。我有一段 Javascript 代码,用于标识应用程序正在运行的浏览器。如果浏览器是 Firefox,则将执行特定的代码块,否则将执行另一个块代码。使用 IE 11 我遇到了一个奇怪的问题。浏览器(即 11)将自己识别为 Mozilla。
javascrip code :
脚本代码:
if ($.browser.mozilla) {
if (location.pathname == "/Stats/Reports") { // This is for local env.
$("#prntCss").attr("href", "../../../Content/SitePrint_FF.css");
}
else {
$("#prntCss").attr("href", "../../Content/SitePrint_FF.css");
$("#rptPrntCss").attr("href", "../../Content/reportPrintStyles_FF.css");
}
回答by Ricardo Polo Jaramillo
Yes. IE 11 doesnt say it is IE anymore, it says it is Mozilla.
是的。IE 11 不再说它是 IE,而是说它是 Mozilla。
Althoug, all IE versions respond the word Trident(its layout engine) in all of its versions.
尽管如此,所有 IE 版本在其所有版本中都响应单词Trident(其布局引擎)。
So something like this could work in your javascript
所以这样的事情可以在你的 javascript 中工作
<script type="text/javascript">
CheckIE();
function CheckIE()
{
var Browser;
Browser = navigator.userAgent;
if (Browser.indexOf("Trident") == -1)
{
//WHATHEVER YOU WANT IF IT IS NOT INTERNET EXPLORER
}
}
</script>
回答by Andrei
Yes, it does:
是的,它确实:
The compatible ("compatible") and browser ("MSIE") tokens have been removed.
...
These changes help prevent IE11 from being (incorrectly) identified as an earlier version.
兼容(“兼容”)和浏览器(“MSIE”)令牌已被删除。
...
这些更改有助于防止 IE11 被(错误地)识别为早期版本。
Still there are some ways to detect it (search for "How to detect ie11"), but your best bet is to remove browser-detection code at all.
仍然有一些方法可以检测它(搜索“如何检测 ie11”),但最好的办法是完全删除浏览器检测代码。
回答by vmg
Take a look at User agent string of IE 11: http://msdn.microsoft.com/en-us/library/ie/hh869301(v=vs.85).aspx
看看 IE 11 的用户代理字符串:http: //msdn.microsoft.com/en-us/library/ie/hh869301(v=vs.85).aspx
Now it says:
现在它说:
Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko
Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) 像 Gecko
And more details: http://www.nczonline.net/blog/2013/07/02/internet-explorer-11-dont-call-me-ie/
更多详情:http: //www.nczonline.net/blog/2013/07/02/internet-explorer-11-dont-call-me-ie/
I think that this is the reason.
我认为这就是原因。
回答by Culyx
This is because IE 11 has a different style of user agent strings then previous versions of IE
这是因为 IE 11 的用户代理字符串样式与以前版本的 IE 不同
http://msdn.microsoft.com/library/ms537503.aspx
http://msdn.microsoft.com/library/ms537503.aspx
User-Agent: Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko