Skip to content

Instantly share code, notes, and snippets.

@ingozoell
Last active February 22, 2017 17:07
Show Gist options
  • Save ingozoell/45d3bfda5804de97bead6c0ab9da66ae to your computer and use it in GitHub Desktop.
Save ingozoell/45d3bfda5804de97bead6c0ab9da66ae to your computer and use it in GitHub Desktop.
Browser Detection JS – HTML Class
(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