- 正则表达式匹配
- function userBrowser(){
- var browserName=navigator.userAgent.toLowerCase();
- if(/msie/i.test(browserName) && !/opera/.test(browserName)){
- alert("IE");
- return ;
- }else if(/firefox/i.test(browserName)){
- alert("Firefox");
- return ;
- }else if(/chrome/i.test(browserName) && /webkit/i.test(browserName) && /mozilla/i.test(browserName)){
- alert("Chrome");
- return ;
- }else if(/opera/i.test(browserName)){
- alert("Opera");
- return ;
- }else if(/webkit/i.test(browserName) &&!(/chrome/i.test(browserName) && /webkit/i.test(browserName) && /mozilla/i.test(browserName))){
- alert("Safari");
- return ;
- }else{
- alert("unKnow");
- }
- }
var sUserAgent = navigator.userAgent;
//检测是否Opera浏览器
var isOpera = sUserAgent.indexOf("Opera")>-1
//检测是否Safari
var isKHTML = sUserAgent.indexOf("KHTML")>-1
|| sUserAgent.indexOf("Konqueror")>-1
|| sUserAgent.indexOf("AppleWebKit")>-1;
//检测IE
var isIE = sUserAgent.indexOf("compatible") > -1
&&sUserAgent.indexOf("MSIE") > -1
&&!isOpera;
//检测Firfox
var isFF = sUserAgent.indexOf("Firefox")>-1&&!isKHTML;
//检测Chrome浏览器
var isChrome = sUserAgent.indexOf("AppleWebKit")>-1;