Created
September 17, 2014 13:33
-
-
Save yanknudtskov/8ce584e44dc27c2569f3 to your computer and use it in GitHub Desktop.
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(){ | |
$('body').addClass(detectBrowserAndVersion); | |
}); | |
function detectBrowserAndVersion() | |
{ | |
var user_agent = navigator.userAgent, user_agent_version, user_agent_match = user_agent.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || []; | |
if(/trident/i.test(user_agent_match[1])) | |
{ | |
user_agent_version = /\brv[ :]+(\d+)/g.exec(user_agent) || []; | |
return 'IE '+(user_agent_version[1] || ''); | |
} | |
if(user_agent_match[1] === 'Chrome') | |
{ | |
user_agent_version = user_agent.match(/\bOPR\/(\d+)/) | |
if(user_agent_version !== null) | |
return 'Opera '+user_agent_version[1]; | |
} | |
user_agent_match = user_agent_match[2] ? [user_agent_match[1], user_agent_match[2]]: [navigator.appName, navigator.appVersion, '-?']; | |
if( ( user_agent_version = user_agent.match( /version\/(\d+)/i ) ) !== null ) | |
user_agent_match.splice(1, 1, user_agent_version[1]); | |
return user_agent_match.join(' ').toLowerCase(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment