【轉】判斷瀏覽器版本是不是ie8如下瀏覽器,若是是調到提示換更高級版本瀏覽器頁面

轉自:判斷瀏覽器版本是不是ie8如下瀏覽器,若是是調到提示換更高級版本瀏覽器頁面html

(function(window) {
    var theUA = window.navigator.userAgent.toLowerCase();
    if ((theUA.match(/msie\s\d+/) && theUA.match(/msie\s\d+/)[0]) || (theUA.match(/trident\s?\d+/) && theUA.match(/trident\s?\d+/)[0])) {
        var ieVersion = theUA.match(/msie\s\d+/)[0].match(/\d+/)[0] || theUA.match(/trident\s?\d+/)[0];
        if (ieVersion < 9) {
            var str = "你的瀏覽器版本太low了\n已經和時代脫軌了 :(";
            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;width: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

 

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";
		    }
	}
}
相關文章
相關標籤/搜索