Created
April 23, 2015 06:43
-
-
Save masarakki/88da375d88db66413e53 to your computer and use it in GitHub Desktop.
snkn.js checkBrowser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkBrowser(){ | |
var a=''; | |
var b={}; | |
b.name=window.navigator.userAgent.toLowerCase(); | |
b.platform=window.navigator.platform.toLowerCase(); | |
b.isMac=(b.platform.indexOf('mac')>=0); | |
b.isWin=(b.platform.indexOf('win')>=0); | |
b.isCrOS=(b.platform.indexOf('linux')>=0 && b.name.indexOf('cros')>=0); | |
b.isIE=(b.name.indexOf('msie')>=0||b.name.indexOf('trident')>=0); | |
b.isSafari=b.name.indexOf('safari')>=0; | |
b.isChrome=b.name.indexOf('chrome')>=0; | |
b.isFirefox=b.name.indexOf('firefox')>=0; | |
b.isiPhone=b.name.indexOf('iphone')>=0; | |
b.isiPod=b.name.indexOf('ipod')>=0; | |
b.isiPad=b.name.indexOf('ipad')>=0; | |
b.isiOS=(b.isiPhone||b.isiPod||b.isiPad); | |
b.isAndroid=b.name.indexOf('android')>=0; | |
b.isTablet=(b.isiPad||(b.isAndroid&&b.name.indexOf('mobile')<0)); | |
if (b.isMac) { | |
b.verArray=/(mac\sos\sx)\s([0-9]+)[_\.]([0-9]+)[_\.]?([0-9]?)/.exec(b.name); | |
if (b.verArray) { | |
b.osMjrVer=parseInt(b.verArray[2]); | |
b.osMinVer=parseInt(b.verArray[3]) | |
} | |
} else if (b.isWin){ | |
if (b.name.match(/win(dows )?nt 6\.3/)) { | |
b.osMjrVer=parseInt(8); | |
b.osMinVer=parseInt(1) | |
} else if (b.name.match(/win(dows )?nt 6\.2/)) { | |
b.osMjrVer=parseInt(8); | |
b.osMinVer=parseInt(0) | |
} else if (b.name.match(/win(dows )?nt 6\.1/)) { | |
b.osMjrVer=parseInt(7); | |
b.osMinVer=parseInt(0) | |
} else if (b.name.match(/win(dows )?nt 6\.0/)) { | |
b.osMjrVer=parseInt(6); | |
b.osMinVer=parseInt(0) | |
} else { | |
b.osMjrVer=parseInt(5); | |
b.osMinVer=parseInt(0) | |
} | |
} | |
if (b.isIE) { | |
b.verArray=/(msie|rv:?)\s?([0-9]{1,})([\.0-9]{1,})/.exec(b.name); | |
if (b.verArray) { | |
b.ver=parseInt(b.verArray[2]) | |
} | |
} | |
if (b.isiOS||b.isAndroid) { | |
return false | |
} else if (b.isMac&&b.osMjrVer*10+b.osMinVer>=106) { | |
if(b.isSafari||b.isChrome||b.isFirefox){ | |
return true | |
} | |
} else if (b.isWin&&b.osMjrVer>=6) { | |
if (b.isIE&&b.ver>=9) { | |
return true | |
} else if (b.isSafari||b.isChrome||b.isFirefox) { | |
return true | |
} | |
} else if (b.isCrOS) { | |
return true | |
} | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment