Created
January 8, 2018 20:34
-
-
Save davidverhage/cd55c08ec1cf30806fd693d5d2f1cfd3 to your computer and use it in GitHub Desktop.
Dirty Mobile Sniffer
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
/** | |
* Quick & dirty browser sniff to detect mobile devices. | |
*/ | |
var html = document.getElementsByTagName('html')[0]; | |
var staticClass = 'static-site' | |
var dynamicClass = 'dynamic-site' | |
if ( | |
navigator.userAgent.match(/Android/i) || | |
navigator.userAgent.match(/webOS/i) || | |
navigator.userAgent.match(/iPhone/i) || | |
navigator.userAgent.match(/iPod/i) || | |
navigator.userAgent.match(/iPad/i) || | |
navigator.userAgent.match(/BlackBerry/i) || | |
navigator.userAgent.match(/IEMobile/i) || | |
navigator.userAgent.match(/Opera Mini/i) | |
) { | |
window.isMobile = true; | |
} | |
var addClass = window.isMobile ? staticClass : dynamicClass; | |
html.className += html.className ? ' ' + addClass : addClass; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment