Last active
August 29, 2015 14:07
-
-
Save 0xregulus/24bacd049e4c0f6403d8 to your computer and use it in GitHub Desktop.
Get Web Browser, version and OS
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 get_browser(){ | |
var ua=navigator.userAgent,tem,M=ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || []; | |
if(/trident/i.test(M[1])){ | |
tem=/\brv[ :]+(\d+)/g.exec(ua) || []; | |
return 'IE '+(tem[1]||''); | |
} | |
if(M[1]==='Chrome'){ | |
tem=ua.match(/\bOPR\/(\d+)/) | |
if(tem!=null) {return 'Opera '+tem[1];} | |
} | |
M=M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?']; | |
if((tem=ua.match(/version\/(\d+)/i))!=null) {M.splice(1,1,tem[1]);} | |
return M[0]; | |
} | |
function get_browser_version(){ | |
var ua=navigator.userAgent,tem,M=ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || []; | |
if(/trident/i.test(M[1])){ | |
tem=/\brv[ :]+(\d+)/g.exec(ua) || []; | |
return 'IE '+(tem[1]||''); | |
} | |
if(M[1]==='Chrome'){ | |
tem=ua.match(/\bOPR\/(\d+)/) | |
if(tem!=null) {return 'Opera '+tem[1];} | |
} | |
M=M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?']; | |
if((tem=ua.match(/version\/(\d+)/i))!=null) {M.splice(1,1,tem[1]);} | |
return M[1]; | |
} | |
function get_os() { | |
var OSName="unknown OS"; | |
if (navigator.userAgent.match(/Windows/i)) | |
OSName="Windows"; | |
if (navigator.userAgent.match(/Mac/i)) | |
OSName="OSX"; | |
if (navigator.userAgent.match(/Linux/i)) | |
OSName="Linux"; | |
if (navigator.userAgent.match(/Android/i)) | |
OSName="Android"; | |
if (navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i)) | |
OSName="iOS"; | |
return OSName; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment