Skip to content

Instantly share code, notes, and snippets.

@burners77
Last active April 2, 2024 15:13
Show Gist options
  • Save burners77/5160231 to your computer and use it in GitHub Desktop.
Save burners77/5160231 to your computer and use it in GitHub Desktop.
Detect mobile devices script
<script type="text/javascript">
var mobile = (/iphone|ipod|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
if (mobile) {
do something;
}
</script>
<script type="text/javascript">
var isAndroid = (/android/i.test(navigator.userAgent.toLowerCase()));
if (isAndroid) {
// alert("Android");
if (screen.width < 800) {
// alert("android portrait");
do something;
} else if (screen.height < 800) {
do something;
//alert("android landscape");
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment