Last active
August 29, 2015 14:17
-
-
Save yxkelan/ab4208690c83b99f4747 to your computer and use it in GitHub Desktop.
JS Bin// source http://jsbin.com/howaza GET IE version.
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
var testCases = [ | |
["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36", -1], | |
["Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Firefox/31.0", -1], | |
["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/600.1.17 (KHTML, like Gecko) Version/8.0 Safari/600.1.17", -1], | |
["Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36", -1], | |
["Mozilla/5.0 (Windows NT 6.2; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0", -1], | |
["Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)", 7], | |
["Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0)", 10], | |
["Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)", 9], | |
["Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)", 8], | |
["Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko", 11] | |
]; | |
function testIe(){ | |
var numOfCases = testCases.length; | |
for (var i =0; i < numOfCases; i++) { | |
var agent = testCases[i][0], | |
version = testCases[i][1]; | |
console.log(getIEversion(agent) === version); | |
} | |
} | |
function getIEversion(str){ | |
var sl = str.toLowerCase(); | |
if (sl.indexOf('msie')!== -1) { | |
return parseInt(sl.split('msie')[1], 10); | |
} | |
if(sl.indexOf('trident')!== -1) { | |
return parseInt(sl.split(' rv:')[1], 10); | |
} | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment