欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

通过agent判断浏览器版本救命分享

程序员文章站 2022-10-10 19:09:49
复制代码 代码如下:public static string getbrowser(string useragent) {  if(useragent=...

复制代码 代码如下:

public static string getbrowser(string useragent) {
  if(useragent==null||useragent.trim().length()<1){
   return "unknow ";
  }
  string[]brorseren=new string[]{
    "myie2",
    "firefox",
    "kugoosoft",
    "lbbrowser",
    "theword",
    "qq",
    "maxthon",
    "biduplayerbrowser",
    "opera",
    "chrome",
    "safari",
    "9a334",
    "ucweb",
    "googlebot",
    "rv 11.0"};
  string[]brorsercn=new string[]{
    "myie2",
    "firefox",
    "酷狗",
    "猎豹",
    "世界之窗",
    "qq",
    "maxthon",
    "百度影音",
    "opera",
    "chrome",
    "safari",
    "360",
    "ucweb",
    "googlebot",
    "ie 11.0"};
  for(int i=0;i<brorseren.length;i++){
   if (useragent.indexof(brorseren[i]) > -1) {
    return brorsercn[i];
   }
  }
  if (useragent.indexof("msie") > -1) {
   if(useragent.indexof("msie 9.0")>-1){
    return "ie 9.0";
   }else if(useragent.indexof("msie 10.0")>-1){
    return "ie 10.0";
   }else if(useragent.indexof("msie 8.0")>-1){
    return "ie 8.0";
   }else if(useragent.indexof("msie 7.0")>-1){
    return "ie 7.0";
   }else if(useragent.indexof("msie 6.0")>-1){
    return "ie 6.0";
   }
   return "ie";
  }
  return "unknow browser";
 }