Created
August 2, 2016 14:42
-
-
Save kopiro/03b240605860e89d3611c2ef99743831 to your computer and use it in GitHub Desktop.
Browser/OS detection
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
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