检测是否有任何类型的IE(MSIE)

Wor*_*ork 49 javascript php jquery internet-explorer

我不想让用户使用Microsoft Internetexplorer(任何版本)访问我的网站.

到目前为止我发现的是检测它是否低于或等于10版本.

一个非常令人讨厌的事情:Internetexplorer> v10不承认自己是一名InternetExplorer.

到目前为止我发现并尝试过的内容:

if(navigator.appVersion.indexOf("MSIE")!=-1){
alert("You use IE. That´s no good.");
}
Run Code Online (Sandbox Code Playgroud)

要么

if ( $.browser.msie ) {
alert( $.browser.version );
}
Run Code Online (Sandbox Code Playgroud)

http://msdn.microsoft.com/en-us/library/ie/ms537509%28v=vs.85%29.aspx

如果有javascript,jquery或php,我会使用任何解决方案.

Top*_*ons 85

这对我来说可以检测任何版本的IE 5-11(Internet Explorer)(2014年8月5日):

if (navigator.appName == 'Microsoft Internet Explorer' ||  !!(navigator.userAgent.match(/Trident/) || navigator.userAgent.match(/rv:11/)) || (typeof $.browser !== "undefined" && $.browser.msie == 1))
{
  alert("Please dont use IE.");
}
Run Code Online (Sandbox Code Playgroud)

  • 仅供参考,截至2015年8月,这对我不起作用.有趣的是(恼人地),navigator.appName设置为Netscape而不是Microsoft Internet Explorer. (4认同)
  • 最好的警报信息.!从3天开始,我的生活变得悲惨 (4认同)
  • 我确认最新版本的IE(不是Edge)将"Netscape"作为navigator.appName. (3认同)
  • ```navigator.userAgent.match(/ rv:11 /)```你必须修复这个,因为它在你的正则表达式字符串中不包含``:``标记 (2认同)

Sar*_*nga 27

这是因为Internet Explorer的每个版本都会更新用户代理字符串.

MSIE在Internet Explorer 11中删除了令牌并$.browser用于navigator.userAgent确定平台,并在jQuery 1.9中将​​其删除.

您可以使用以下代码来确定具有纯java脚本的浏览器.

var isIE = !!navigator.userAgent.match(/Trident/g) || !!navigator.userAgent.match(/MSIE/g);

if(isIE){
 alert("IE"); 
}
else{
 alert("Not IE");   
}
Run Code Online (Sandbox Code Playgroud)

谢谢!

  • `const isIE = /Trident|MSIE/.test(navigator.userAgent);`是更短的等价物 (9认同)

ins*_*ns0 7

如果你不是因为用户目前使用的版本,你可以尝试使用它来检测浏览器是否支持 Conditional Compilation Statements

http://msdn.microsoft.com/en-us/library/7kx09ct1%28v=vs.80%29.aspx

if(/*@cc_on!@*/false)
{
    // You use IE. That´s no good.
    alert("oh my god");
}
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

70352 次

最近记录:

8 年,10 月 前