Friday, April 4, 2014

[Javascript] Example to check mobile user agent / browser

This is used by a web project and checked by chrome, IE, Fireox, Android 2.2, iOS Safari.

<script type="text/javascript">
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
    //Do sth
    alert("You are using Moblie");
} else {
    //Do sth
    alert("You are using deskTop");
}
</script>

Reference:
From Stack Overflow but can’t found the link again.

No comments :

Post a Comment