且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检测浏览器是IE 7还是更低?

更新时间:2022-10-16 16:23:18

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

考虑重构:


  • 在设置为

后设置返回

  var redir =main.html; 
if(/ MSIE(\ d + \.\d +); /。test(navigator.userAgent))
{
var ieversion = new Number(RegExp。$ 1);
if(ieversion {
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;