Last active
November 13, 2019 15:57
-
-
Save Xaz16/30924c1802a54afab275d0df597dd5b0 to your computer and use it in GitHub Desktop.
Check useragent or platform of client navigator and apply it on body
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 platform = { | |
ipad: /iPad/.test(navigator.userAgent) && !window.MSStream, | |
ios: /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream, | |
safari: navigator.userAgent.indexOf('Safari') !== -1 && navigator.userAgent.indexOf('Chrome') === -1 && !window.MSStream, | |
mac: navigator.platform.toLowerCase().indexOf('mac') >= 0 && !window.MSStream, | |
android: /(android)/i.test(navigator.userAgent) || navigator.platform.toLowerCase().indexOf("android") > -1 && !window.MSStream, | |
firefox: navigator.userAgent.toLowerCase().indexOf('firefox') > -1 && !window.MSStream, | |
windows: navigator.platform.indexOf('Win') > -1 && !window.MSStream, | |
ie: !!window.MSInputMethodContext && !!document.documentMode && !window.MSStream | |
}; | |
for(key in platform) { | |
document.body.classList.toggle(key, platform[key]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment