zoukankan      html  css  js  c++  java
  • 【转】判断浏览器版本是否是ie8以下浏览器,如果是调到提示换更高级版本浏览器页面

    转自:判断浏览器版本是否是ie8以下浏览器,如果是调到提示换更高级版本浏览器页面

    (function(window) {
        var theUA = window.navigator.userAgent.toLowerCase();
        if ((theUA.match(/msiesd+/) && theUA.match(/msiesd+/)[0]) || (theUA.match(/tridents?d+/) && theUA.match(/tridents?d+/)[0])) {
            var ieVersion = theUA.match(/msiesd+/)[0].match(/d+/)[0] || theUA.match(/tridents?d+/)[0];
            if (ieVersion < 9) {
                var str = "你的浏览器版本太low了 已经和时代脱轨了 :(";
                var str2 = "推荐使用:<a href='https://www.baidu.com/s?ie=UTF-8&wd=%E8%B0%B7%E6%AD%8C%E6%B5%8F%E8%A7%88%E5%99%A8' target='_blank' style='color:#cc0'>谷歌</a>,"
                + "<a href='https://www.baidu.com/s?ie=UTF-8&wd=%E7%81%AB%E7%8B%90%E6%B5%8F%E8%A7%88%E5%99%A8' target='_blank' style='color:#cc0'>火狐</a>,"
                + "<a href='https://www.baidu.com/s?ie=UTF-8&wd=%E7%8C%8E%E8%B1%B9%E6%B5%8F%E8%A7%88%E5%99%A8' target='_blank' style='color:#cc0'>猎豹</a>,其他双核急速模式";
                document.writeln("<pre style='text-align:center;color:#fff; height:100%;border:0;position:fixed;top:0;left:0;100%;z-index:1234'>" + 
                "<h2 style='padding-top:200px;margin:0'><strong>" + str + "<br/></strong></h2><p>" + 
                str2 + "</p><h2 style='margin:0'><strong>如果你的使用的是双核浏览器,请切换到极速模式访问<br/></strong></h2></pre>");
                document.execCommand("Stop");
            };
        }
    })(window);

    Java中判断

    String theUA = request.getHeader("user-agent").toLowerCase();
    Pattern pattern1 = Pattern.compile("(msie)\s\d+");
    Matcher matcher1 = pattern1.matcher(theUA);
    if (matcher1.find()){
    	String strVersion = matcher1.group();
    	Pattern pattern2 = Pattern.compile("\d+");
    	Matcher matcher2 = pattern2.matcher(strVersion);
    	if(matcher2.find()){
    		String intVersion = matcher2.group();
    		int ieVersion = Integer.parseInt(intVersion);
    		if(ieVersion < 9){
    		        return "IE版本小于9.0";
    		    }
    	}
    }
    

      

  • 相关阅读:
    优先队列
    Problem W UVA 662 二十三 Fast Food
    UVA 607 二十二 Scheduling Lectures
    UVA 590 二十一 Always on the run
    UVA 442 二十 Matrix Chain Multiplication
    UVA 437 十九 The Tower of Babylon
    UVA 10254 十八 The Priest Mathematician
    UVA 10453 十七 Make Palindrome
    UVA 10163 十六 Storage Keepers
    UVA 1252 十五 Twenty Questions
  • 原文地址:https://www.cnblogs.com/zhanglm125/p/6228580.html
Copyright © 2011-2022 走看看