javascript检测浏览器及其版本的代码


JavaScript #浏览器2012-05-19 00:04
 getBrowser : function(){
  var browser = {
   msie: false, firefox: false, opera: false, safari: false, 
   chrome: false, netscape: false, appname: 'unknown', version: 0
  },
  userAgent = window.navigator.userAgent.toLowerCase();
  if ( /(msie|firefox|opera|chrome|netscape)\D+(\d[\d.]*)/.test( userAgent ) ){
   browser[RegExp.$1] = true;
   browser.appname = RegExp.$1;
   browser.version = RegExp.$2;
  } else if ( /version\D+(\d[\d.]*).*safari/.test( userAgent ) ){ // safari
   browser.safari = true;
   browser.appname = 'safari';
   browser.version = RegExp.$2;
  }
  return browser.appname + browser.version;
 }

相关文章

粤ICP备11097351号-1