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

Pro*_*raz 6 javascript jquery internet-explorer internet-explorer-8

我想知道是否有可能显示警告或打开弹出窗口,这可能会将IE更新为最新版本或使用Firefox/Chrome/Safari,而浏览器是Internet Explorer IE8或更早版本...

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

<!--[if lt IE 9]>
...i should use code here...
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

使用jQuery欺骗浏览器并加载jQuery lib是否明智?或者是否更好地使用常规JavaScript以避免旧版浏览器的其他问题?

Cla*_*edi 6

你可以使用像这样

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

网页仍然在透明背景后面可见,但是可以防止访问它.我们的想法是强制用户从IE6升级并避免网站因IE6中网站无法正确呈现而造成的恶劣声誉.

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

虽然创建时是为了与IE6用户一起使用,但使用正确的参数可以将它用于您的场景.


ant*_*njs 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);
    }
    
    Run Code Online (Sandbox Code Playgroud)
  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]>
    
    Run Code Online (Sandbox Code Playgroud)

参考:更有效地检测Windows Internet Explorer


Dav*_*hta 5

<script> var ISOLDIE = false; </script>
<!--[if lt IE 9]>
     <script> var ISOLDIE = true; </script>
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

然后,您想要在代码中绘制支持旧版IE的行:

<script>

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

</script>
Run Code Online (Sandbox Code Playgroud)

完全删除IE8支持通常不是一个好主意,这就是为什么我认为上面的解决方案是一个很好的折衷,因为你可以将它添加到你的网站/网络应用程序的组件,这些组件根本无法支持IE8,但是你可能(可能)仍然支持IE8在您网站的其他区域.