检测浏览器是IE 7还是更低? [英] Detect whether browser is IE 7 or lower?

查看:106
本文介绍了检测浏览器是IE 7还是更低?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我将在我的网站上添加一个重定向,将每个使用ie 7或更低版​​本的用户折腾到不同的页面,并提供此JavaScript,但它似乎已停止工作。

 < script type =text / javascript> 
if(/ MSIE(\ d + \.\d +); /。test(navigator.userAgent)){//测试MSIE x.x;
var ieversion = new Number(RegExp。$ 1)//捕获xx部分并以数字形式存储
if(ieversion <= 8)
window.location =ie.html
}
window.location =main.html
< / script>


解决方案

您的代码始终导致< C $ C> main.html中。即使代码落入< 8 ,如果设置为<$ c,您将会掉到

考虑重构:


  • 在设置为

后设置返回

  var redir =main.html; 
if(/ MSIE(\ d + \.\d +); /。test(navigator.userAgent))
{
var ieversion = new Number(RegExp。$ 1);
if(ieversion <= 8)
{
redir =ie.html;
}
}
window.location = redir;


So i am going to add a redirect to my site to toss every one that is using ie 7 or lower off to a different page and came up with this JavaScript, but it seems to have stopped working.

<script type="text/javascript">
 if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
  var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
   if (ieversion<=8)
    window.location = "ie.html" 
   }
   window.location = "main.html"
</script>

解决方案

Your code is always resulting to having gone to main.html. Even when the code falls into <8, you'll fall out of the if into setting to main.

Consider refactoring by either:

  • setting a return after setting to ie.

or

var redir="main.html";
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
{ 
   var ieversion=new Number(RegExp.$1);
   if (ieversion<=8)
   {
      redir = "ie.html";
   }
}
window.location = redir;

这篇关于检测浏览器是IE 7还是更低?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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