Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
58
rated 0 times [  63] [ 5]  / answers: 1 / hits: 15916  / 13 Years ago, mon, may 23, 2011, 12:00:00

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>

More From » html

 Answers
2

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;

[#92094] Sunday, May 22, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
loganl

Total Points: 424
Total Questions: 86
Total Answers: 112

Location: Zimbabwe
Member since Thu, Jul 21, 2022
2 Years ago
;