Last active
February 22, 2017 17:07
-
-
Save ingozoell/45d3bfda5804de97bead6c0ab9da66ae to your computer and use it in GitHub Desktop.
Browser Detection JS – HTML Class
This file contains hidden or 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(){ | |
var htmlTag = document.getElementsByTagName("html")[0]; | |
if ( navigator.userAgent.indexOf("MSIE 10.0") > -1 ) { | |
htmlTag.className += ' ie10'; | |
} | |
if ( !!navigator.userAgent.match(/Trident.*rv\:11\./) ) { | |
htmlTag.className += ' ie11'; | |
} | |
if ( /(iPad|iPhone|iPod)/g.test(navigator.userAgent) ) { | |
htmlTag.className += ' is-ios'; | |
} | |
var user_agent = navigator.userAgent.toLowerCase(); | |
if ( user_agent.indexOf("android") > -1 ) { | |
htmlTag.className += ' is-android'; | |
} | |
if ( -1 !== navigator.userAgent.indexOf('Mac OS X') ) { | |
htmlTag.className += ' is-os-x'; | |
} | |
if ( /chrom(e|ium)/.test(navigator.userAgent.toLowerCase()) ) { | |
htmlTag.className += ' is-chrome'; | |
} | |
if ( -1 !== navigator.userAgent.indexOf('Firefox') ) { | |
htmlTag.className += ' is-firefox'; | |
} | |
if ( -1 !== navigator.userAgent.indexOf('Safari') && -1 === navigator.userAgent.indexOf('Chrome') ) { | |
htmlTag.className += ' is-safari'; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment