Skip to content

Instantly share code, notes, and snippets.

@CooLNuanfeng
Created July 23, 2014 07:16
Show Gist options
  • Save CooLNuanfeng/cf651dd3c356b7f99306 to your computer and use it in GitHub Desktop.
Save CooLNuanfeng/cf651dd3c356b7f99306 to your computer and use it in GitHub Desktop.
浏览器判断
/*
* @link :http://browserhacks.com/
* IE篇
*/
var ie6=!-[1,]&&!window.XMLHttpRequest; //IE6为true,其他都为false
var isIE = !!window.ActiveXObject; //ie6-10都为true, ie11为false
/*返回IE6-9的版本号*/
var _IE = (function(){
var v = 3, div = document.createElement('div'), all = div.getElementsByTagName('i');
while (
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
all[0]
);
return v > 4 ? v : false ;
}());
/*
* @link :http://browserhacks.com/
* chrome篇
*/
var isChromium = !!window.chrome; //Chromium为true.
var isChrome = !!window.chrome && !!window.chrome.webstore; //chrome为true.
/*
* @link :http://browserhacks.com/
* Firefox篇
*/
var isFF = !!window.sidebar;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment