2013-02-25 63 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/">