Skip to content

Instantly share code, notes, and snippets.

@kopiro
Created August 2, 2016 14:42
Show Gist options
  • Save kopiro/03b240605860e89d3611c2ef99743831 to your computer and use it in GitHub Desktop.
Save kopiro/03b240605860e89d3611c2ef99743831 to your computer and use it in GitHub Desktop.
Browser/OS detection
var IS_IOS = /iphone|ipad|ipod/i.test(navigator.userAgent);
var IS_IEMOBILE = /iemobile/i.test(navigator.userAgent);
var IS_ANDROID = /android/i.test(navigator.userAgent);
var IS_IE = /msie/i.test(navigator.userAgent);
var IS_TOUCH_DEVICE = (function() {
var el = document.createElement('div');
el.setAttribute('ongesturestart', 'return;');
return typeof el.ongesturestart === "function";
})();
// Add rules as class to HTML
var $html = $('html');
if (IS_IOS) $html.addClass('is-ios');
if (IS_ANDROID) $html.addClass('is-android');
if (IS_IEMOBILE) $html.addClass('is-iemobile');
if (IS_IE) $html.addClass('is-ie');
if (IS_TOUCH_DEVICE) $html.addClass('is-touch');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment