首页 > 代码库 > 判断访问站点的浏览器类型
判断访问站点的浏览器类型
function browserinfo() { var Browser_Name = navigator.appName; var Browser_Version = parseFloat(navigator.appVersion); var Browser_Agent = navigator.userAgent; var Actual_Version="", Actual_Name=""; var is_IE = (Browser_Name == "Microsoft Internet Explorer");// 判读是否为ie浏览器 var is_NN = (Browser_Name == "Netscape");// 判断是否为netscape浏览器 //var is_op = (Browser_Name == "Opera");// 判断是否为Opera浏览器 if (is_NN) { // upper 5.0 need to be process,lower 5.0 return directly if (Browser_Version >= 5.0) { if (Browser_Agent.indexOf("Netscape") != -1) { var Split_Sign = Browser_Agent.lastIndexOf("/"); var Bname = Browser_Agent.substring(0, Split_Sign); var Split_sign2 = Bname.lastIndexOf(" "); Actual_Version = Browser_Agent.substring(Split_Sign + 1, Browser_Agent.length); Actual_Name = Bname.substring(Split_sign2 + 1, Bname.length); } if (Browser_Agent.indexOf("Firefox") != -1) { var Split_Sign = Browser_Agent.lastIndexOf("/"); var Version = Browser_Agent.lastIndexOf(" "); Actual_Version = Browser_Agent.substring(Split_Sign + 1, Browser_Agent.length); Actual_Name = Browser_Agent.substring(Version + 1, Split_Sign); } if (Browser_Agent.indexOf("Safari") != -1) { if (Browser_Agent.indexOf("Chrome") != -1) { var Split_Sign = Browser_Agent.lastIndexOf(" "); var Version = Browser_Agent.substring(0, Split_Sign); ; var Split_Sign2 = Version.lastIndexOf("/"); var Bname = Version.lastIndexOf(" "); Actual_Version = Version.substring(Split_Sign2 + 1, Version.length); Actual_Name = Version.substring(Bname + 1, Split_Sign2); } else { var Split_Sign = Browser_Agent.lastIndexOf("/"); var Version = Browser_Agent.substring(0, Split_Sign); ; var Split_Sign2 = Version.lastIndexOf("/"); var Bname = Browser_Agent.lastIndexOf(" "); Actual_Version = Browser_Agent.substring(Split_Sign2 + 1, Bname); Actual_Name = Browser_Agent .substring(Bname + 1, Split_Sign); } } } else { Actual_Version = Browser_Version; Actual_Name = Browser_Name; } } else if (is_IE) { var Version_Start = Browser_Agent.indexOf("MSIE"); var Version_End = Browser_Agent.indexOf(";", Version_Start); Actual_Version = Browser_Agent.substring(Version_Start + 5, Version_End); Actual_Name = Browser_Name; if (Browser_Agent.indexOf("Maxthon") != -1 || Browser_Agent.indexOf("MAXTHON") != -1) { var mv = Browser_Agent.lastIndexOf(" "); var mv1 = Browser_Agent.substring(mv, Browser_Agent.length - 1); mv1 = "遨游版本:" + mv1; Actual_Name += "(Maxthon)"; Actual_Version += mv1; } } else if (Browser_Agent.indexOf("Opera") != -1) { Actual_Name = "Opera"; // var tempstart = Browser_Agent.indexOf("Opera"); // var tempend = Browser_Agent.length; Actual_Version = Browser_Version; } else { Actual_Name = "Unknown Navigator"; Actual_Version = "Unknown Version"; } navigator.Actual_Name = Actual_Name; navigator.Actual_Version = Actual_Version; this.Name = Actual_Name; this.Version = Actual_Version; } function jadgeBrowser() { if(navigator.userAgent.indexOf("MSIE")>0) { return "MSIE"; } if(isFirefox=navigator.userAgent.indexOf("Chrome")>0){ return "Chrome"; } if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){ return "Firefox"; } if(isSafari=navigator.userAgent.indexOf("Safari")>0) { return "Safari"; } if(isCamino=navigator.userAgent.indexOf("Opera")>0){ return "Opera"; } if(isMozilla=navigator.userAgent.indexOf("Sogou/")>0){ return "Sogou"; } return "Unknown Browser"; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。