2013-02-25 62 views
-3

我有一个网站与旧版本的Internet Explorer不兼容。我不想毁掉非IE用户的体验,而是希望将IE用户重定向到同一网站的另一个兼容版本,当他们进入我的网址时。这可能吗?如何根据浏览器重定向用户?

+5

你好,请永远记住谷歌第一!搜索“我如何根据浏览器重定向用户?”似乎产生非常有用的结果;如有必要,请将该技术添加为关键字,例如“javascript”或“html”。谢谢! – 2013-02-25 09:58:56

+0

对不起,我在Google搜索时没有使用这些词,因此我找不到任何有用的东西。如果不事先做一点研究,我就不会开始提问,我很抱歉不方便。 – 2013-02-25 12:51:50

回答

1

this post

navigator.sayswho= (function(){ 
    var N= navigator.appName, ua= navigator.userAgent, tem; 
    var M= ua.match(/(opera|chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i); 
    if(M && (tem= ua.match(/version\/([\.\d]+)/i))!= null) M[2]= tem[1]; 
    M= M? [M[1], M[2]]: [N, navigator.appVersion, '-?']; 
    return M; 

})(); navigator.sayswho [0]是(串)版本

所有你需要做的是:

var browser = navigator.sayswho[0]; 
if(browser == "MSIE") { 
    document.location.href = "you.new.url.html"; 
} 
3

是的,您可以使用IE's conditional comments为旧版IE执行此操作。例如:

<!--[if lt IE 8]> 
<meta http-equiv="refresh" content="0;url=/your/other/page" /> 
<![endif]--> 

IE10不再支持它们,但是你可能不需要用IE10做重定向。

1

有一个评论功能来做到这一点。

<!--[if lte IE 7]> 
    Redirect your page here. 
<![endif]--> 

而对于redirecion本身,你可以使用JavaScript或元标题:

使用JavaScript:

<script>window.location = "http://www.my-new-page.com/"</script> 

与元

<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.my-new-page.com/">