2012-04-06 51 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]-->