Javascript 如果IE8或更早版本,则强制更新浏览器

Javascript 如果IE8或更早版本,则强制更新浏览器,javascript,jquery,internet-explorer,internet-explorer-8,Javascript,Jquery,Internet Explorer,Internet Explorer 8,我想知道,当浏览器是IE IE8或更旧版本时,是否可以显示警告或打开弹出窗口,上面会显示将IE更新到最新版本或使用Firefox/Chrome/Safari来代替 我想我应该在标签中使用下面的代码 <!--[if lt IE 9]> ...i should use code here... <![endif]--> 使用jQuery定义浏览器并加载jQuery库是否明智?还是只使用常规javascript以避免非常旧的浏览器出现额外问题更好?var ISOLDIE=

我想知道,当浏览器是IE IE8或更旧版本时,是否可以显示警告或打开弹出窗口,上面会显示将IE更新到最新版本或使用Firefox/Chrome/Safari来代替

我想我应该在标签中使用下面的代码

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

使用jQuery定义浏览器并加载jQuery库是否明智?还是只使用常规javascript以避免非常旧的浏览器出现额外问题更好?

var ISOLDIE=false;
<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>

如果(死亡){
警报(“您的浏览器当前不支持此功能。请升级。”);
window.location=http://google.com/chrome';
}

完全取消IE8支持通常不是一个好主意,这就是为什么我认为上述解决方案是一个很好的折衷方案,因为您可以将其添加到您的网站/web应用程序的组件中,而这些组件根本无法支持IE8,但您可以(可能)在您网站的其他领域仍然支持IE8。

您可以使用

ie6升级警告是一个小脚本(7.9kb),它显示一条警告消息,礼貌地通知用户将浏览器升级到新版本(提供最新IE、Firefox、Opera、Safari和Chrome的链接)

该网页在透明背景下仍然可见,但无法访问。其想法是强迫用户从IE6升级,避免网站在IE6中无法正确呈现的坏名声

该脚本完全可以用任何语言翻译,非常容易设置(网页中的一行代码和一个参数配置)


虽然是为IE6用户而创建的,但使用正确的参数,您可以在您的场景中使用它。

有一个荷兰网站迫使IE6和更低级别的用户升级浏览器,对“如果IE”代码稍作调整,您可以从任何您喜欢的版本中阻止它

向下滚动到第4步,单击下载或“voorbeeld”进行演示,第一个是顶部横幅,第二个完全阻止页面

唯一的缺点是,它都是荷兰语,所以你必须自己编写信息。

你有两个选择:

  • 分析
    用户代理字符串

    // 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);
    }
    
  • 使用条件注释:

    <!--[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]>
    
    
    您没有使用Internet Explorer


  • 参考:

    IE 10不再支持条件注释。WTF

    在您的站点上,将代码添加到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]-->
    

    有很多方法,但这是迄今为止最优雅的:

    此工具正适合此项工作;使用它。这太严格了,你忽略了世界上大约40%的访问者way@Rodolfo如果他阻止他们进入,那么是的。但如果他只是显示一条横幅消息或模式,上面写着“你的浏览器已过时,请升级”,那么这只会有所帮助。我怀疑大多数IE用户是否完全理解浏览器是什么。@RoryMcCrossan啊,是的,如果只是一个警告,只要网站至少能在IE8上运行(如果IE7也能运行,甚至更好,仍然有10%的用户使用IE7)@Rodolfo这个数据让我成了一只悲伤的熊猫。很好,但如果有人使用旧的IE版本,他们是一个依赖IE特定功能的企业,或者是一个不知道什么是web浏览器,只知道点击“蓝色e”的PC新手。在这种情况下,最好包含用于升级IE和其他浏览器的链接,而不是只包含一个特定的竞争性web浏览器。IE10和IE11已经过时了。现在带铬的边缘是最新的:-)