Check browser type browserutils

Source: Internet
Author: User

Browserutils. Java

Import Java. util. regEx. matcher; import Java. util. regEx. pattern; import javax. servlet. HTTP. httpservletrequest; public class browserutils {// determine whether it is iepublic static Boolean isie (httpservletrequest request) {return request. getheader ("User-Agent "). tolowercase (). indexof ("MSIE")> 0? True: false;}/*** get IE version ** @ Param Request * @ return */public static double getieversion (httpservletrequest request) {double version = 0.0; if (getbrowsertype (request, "MSIE 10.0") {version = 10.0;} If (getbrowsertype (request, "MSIE 9.0") {version = 9.0 ;} if (getbrowsertype (request, "MSIE 8.0") {version = 8.0;} If (getbrowsertype (request, "MSIE 7.0") {version = 7.0 ;} if (getbrowsertype (request, "MSIE 6.0") {version = 6.0;} return version ;} /*** obtain the browser type ** @ Param Request * @ return */public static browsertype getbrowsertype (httpservletrequest request) {browsertype = NULL; If (getbrowsertype (request, "MSIE 10.0") {browsertype = browsertype. ie9;} If (getbrowsertype (request, "MSIE 9.0") {browsertype = browsertype. ie9;} If (getbrowsertype (request, "MSIE 8.0") {browsertype = browse Rtype. IE8;} If (getbrowsertype (request, "MSIE 7.0") {browsertype = browsertype. IE7;} If (getbrowsertype (request, "MSIE 6.0") {browsertype = browsertype. IE6;} If (getbrowsertype (request, "Firefox") {browsertype = browsertype. firefox;} If (getbrowsertype (request, "safari") {browsertype = browsertype. safari;} If (getbrowsertype (request, "Chrome") {browsertype = browsertype. chrome;} If (getbrowsertype (Request, "Opera") {browsertype = browsertype. opera;} If (getbrowsertype (request, "Camino") {browsertype = browsertype. camino;} return browsertype;} Private Static Boolean getbrowsertype (httpservletrequest request, string brosertype) {return request. getheader ("User-Agent "). tolowercase (). indexof (brosertype)> 0? True: false;} private final static string ie9 = "MSIE 9.0"; private final static string IE8 = "MSIE 8.0"; private final static string IE7 = "MSIE 7.0 "; private Final Static string IE6 = "MSIE 6.0"; private final static string Maxthon = "Maxthon"; private final static string QQ = "qqbrowser "; private Final Static string Green = "greenbrowser"; private final static string se360 = "360se"; private final static string Firefox = "Firefox"; private final static string opera = "Opera "; private Final Static string chrome = "Chrome"; private final static string safari = "safari"; private final static string Other = "other"; public static string checkbrowse (httpservletrequest request) {string useragent = request. getheader ("User-Agent"); If (RegEx (opera, useragent) return opera; If (RegEx (chrome, useragent) return chrome; If (RegEx (Firefox, useragent) return Firefox; If (RegEx (Safari, useragent) return Safari; If (RegEx (se360, useragent) return se360; If (RegEx (Green, useragent )) return green; If (RegEx (QQ, useragent) return QQ; If (RegEx (Maxthon, useragent) return Maxthon; If (RegEx (ie9, useragent) return ie9; if (RegEx (IE8, useragent) return IE8; If (RegEx (IE7, useragent) return IE7; If (RegEx (IE6, useragent) return IE6; return other ;} public static Boolean RegEx (string RegEx, string Str) {pattern P = pattern. compile (RegEx, pattern. multiline); matcher M = P. matcher (STR); Return M. find ();}}

Browsertype. Java

 

public enum BrowserType {IE10,IE9,IE8,IE7,IE6,Firefox,Safari,Chrome,Opera,Camino,Gecko}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.