2012-04-06 48 views
6

我不知道是否有可能顯示警告或打開彈出窗口,它會說你的IE瀏覽器升級到最新版本,或者使用Firefox/Chrome/Safari瀏覽器,當IE瀏覽器是IE8以上...強制瀏覽器更新,如果IE8或更舊

我想我應該低於使用該代碼的標籤內...

<!--[if lt IE 9]> 
...i should use code here... 
<![endif]--> 

它是明智的使用jQuery和jQuery的加載LIB deceted瀏覽器?或者,爲了避免使用非常老的瀏覽器出現其他問題,只使用常規javascript會更好嗎?

+0

這個工具正好適合這份工作;用它。 – Jon 2012-04-06 14:28:02

+0

這太嚴格了,你忽略了這個世界上約40%的訪問者 – Rodolfo 2012-04-06 14:28:23

+1

@Rodolfo如果他阻止訪問他們,那麼他是。但是,如果他只是顯示一條標語消息或模式,說'你的瀏覽器已過時,請升級',那麼它只會有所幫助。我懷疑大多數IE用戶完全理解瀏覽器是什麼。 – 2012-04-06 14:29:40

回答

6

你有兩個選擇:

  1. 解析的User-Agent String

    // Returns the version of Internet Explorer or a -1 
    // (indicating the use of another browser). 
    function getInternetExplorerVersion() { 
        var rv = -1; // Return value assumes failure. 
    
        if (navigator.appName == 'Microsoft Internet Explorer') { 
         var ua = navigator.userAgent; 
         var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); 
    
         if (re.exec(ua) != null) { 
          rv = parseFloat(RegExp.$1); 
         } 
        } 
    
        return rv; 
    } 
    
    function checkVersion() { 
        var msg = "You're not using Internet Explorer."; 
        var ver = getInternetExplorerVersion(); 
    
        if (ver > -1) { 
         if (ver >= 9.0) { 
          msg = "You're using a recent copy of Internet Explorer." 
         } 
         else { 
          msg = "You should upgrade your copy of Internet Explorer."; 
         } 
        } 
        alert(msg); 
    } 
    
  2. 使用條件註釋:

    <!--[if gte IE 9]> 
    <p>You're using a recent version of Internet Explorer.</p> 
    <![endif]--> 
    
    <!--[if lt IE 8]> 
    <p>Hm. You should upgrade your copy of Internet Explorer.</p> 
    <![endif]--> 
    
    <![if !IE]> 
    <p>You're not using Internet Explorer.</p> 
    <![endif]> 
    

參考:Detecting Windows Internet Explorer More Effectively

5
<script> var ISOLDIE = false; </script> 
<!--[if lt IE 9]> 
    <script> var ISOLDIE = true; </script> 
<![endif]--> 

然後後來,在任何你想畫線在您的代碼,以支持舊版本的IE:

<script> 

    if(ISOLDIE) { 
      alert("Your browser currently does not support this feature. Please upgrade."); 
      window.location = 'http://google.com/chrome'; 
    } 

</script> 

這通常不是一個好主意,完全刪除IE8的支持,這是爲什麼我認爲上述解決方案是一個很好的折衷方案,因爲您可以將它添加到您的網站/ Web應用程序的組件中,而這些組件無法支持IE8,但是您可能(可能)仍然支持在您網站的其他區域使用IE8。

+0

好,但有可能是,如果某人在老IE版本,他們是一個依賴IE特定功能的企業,或者一個PC新手,他並不真正瞭解網絡瀏覽器,只知道點擊「藍色e」。在這樣的情況下,包含升級IE和其他瀏覽器的鏈接可能會更好,而不僅僅是一個特定的競爭Web瀏覽器。 – 2014-11-25 18:17:35

6

您可以使用類似this

IE6的升級預警是一個小腳本(7.9kb),顯示一條警告消息,禮貌地告知用戶將瀏覽器升級到較新的版本(鏈接提供最新的IE,Firefox,Opera,Safari,Chrome)。

網頁在透明背景下仍然可見,但無法訪問該網頁。這個想法是強制用戶從IE6升級,並避免網站在IE6中無法正確呈現網頁。

該腳本可以在任何語言下完全翻譯,非常易於設置(網頁和一個參數配置中的一行代碼)。

儘管已創建與IE6用戶一起使用,但使用正確的參數可以將其用於您的方案。

2

有這個荷蘭網站強制IE6和低級用戶升級他們的瀏覽器,對「If IE」代碼進行一些調整,你可以阻止你喜歡的任何版本。

http://wijstoppenook.nl/nl/

向下滾動到第4步,點擊下載或「voorbeeld」的演示中,第一個是頂部的橫幅,第二個完全塊的頁面。

唯一的缺點是,它全部在荷蘭,所以你必須編寫自己的信息。

1

IE 10不再支持條件註釋。WTF! Link

0

您的網站上的代碼添加到index.html或index.php文件

其工作也Joomla和WordPress的。

<!--[if IE 5]> 
<script language="Javascript"> 
<!-- 
alert ("It looks like you aren't using Internet Explorer 7. To see our site correctly, please update.") 
//--> 
</script> 
<![endif]--> 
<!--[if IE 5.0]> 
!-- 
alert ("It looks like you aren't using Internet Explorer 7. To see our site correctly, please update.") 
//--> 
</script> 
<![endif]--> 
<!--[if IE 5.5]> 
!-- 
alert ("It looks like you aren't using Internet Explorer 7. To see our site correctly, please update.") 
//--> 
</script> 
<![endif]--> 
<!--[if IE 6]> 
!-- 
alert ("It looks like you aren't using Internet Explorer 7. To see our site correctly, please update.") 
//--> 
</script> 
<![endif]--> 

<!--[if IE 7]> 
!-- 
alert ("It looks like you aren't using Internet Explorer 7. To see our site correctly, please update.") 
//--> 
</script> 
<![endif]--> 

<!--[if IE 8]> 
!-- 
alert ("It looks like you aren't using Internet Explorer 8. To see our site correctly, please update.") 
//--> 
</script> 
<![endif]-->