Last active
November 14, 2017 20:30
-
-
Save Tahseenm/d7d801e6e1fd6e7d980cc3647152a4de to your computer and use it in GitHub Desktop.
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
// ------------------------------------------------- \\ | |
// Check Mobile version | |
// ------------------------------------------------- // | |
const USER_AGENT = navigator.userAgent || navigator.vendor || window.opera | |
/** | |
* Detect if the enviroment executing this script is a Windows phone | |
* @returns {boolean} | |
*/ | |
const isWindowsPhone = () => !!USER_AGENT.match(/windows phone/i) | |
/** | |
* Detect if the enviroment executing this script is a Android device | |
* @returns {boolean} | |
*/ | |
const isAndroid = () => !!USER_AGENT.match(/android/i) | |
/** | |
* Detect if the enviroment executing this script is a iOS device | |
* @returns {boolean} | |
*/ | |
const isIOS = () => !!USER_AGENT.match(/iPad|iPhone|iPod/) && !window.MSStream | |
/** | |
* Detect if the enviroment executing this script is a iOS device version 9 and below | |
* @returns {boolean} | |
*/ | |
const isOldIOS = () => isIOS() && !window.matchMedia('(-webkit-video-playable-inline)').matches | |
/** | |
* Detect if the enviroment executing this script is a mobile device | |
* @returns {boolean} | |
*/ | |
const isMobileDevice = () => isWindowsPhone() || isAndroid() || isIOS() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment