检测浏览器是IE 7还是更低? [英] Detect whether browser is IE 7 or lower?
问题描述
因此,我将在我的网站上添加一个重定向,将每个使用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中。即使代码落入 考虑重构: 或 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.
Your code is always resulting to having gone to Consider refactoring by either: or
这篇关于检测浏览器是IE 7还是更低?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!< 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;
<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>
main.html
. Even when the code falls into <8
, you'll fall out of the if
into setting to main
.
return
after setting to ie
.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;