Skip to content

Instantly share code, notes, and snippets.

@Tahseenm
Last active November 14, 2017 20:30
Show Gist options
  • Save Tahseenm/d7d801e6e1fd6e7d980cc3647152a4de to your computer and use it in GitHub Desktop.
Save Tahseenm/d7d801e6e1fd6e7d980cc3647152a4de to your computer and use it in GitHub Desktop.
// ------------------------------------------------- \\
// 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