Skip to content

Instantly share code, notes, and snippets.

@Zillionx
Last active August 29, 2015 14:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zillionx/72249d996058249d283d to your computer and use it in GitHub Desktop.
Save Zillionx/72249d996058249d283d to your computer and use it in GitHub Desktop.
Javascript OS mobile detection with url redirect
/* Zilli 201102
To detect the OS mobile system on the client device,
match the value of navigator.userAgent,
then redirect to mobile url with the location.replace value.
*/
if (navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)
|| navigator.userAgent.match(/Opera Mini/i)
|| navigator.userAgent.match(/IEMobile/i)
) {
location.replace("index-mobile.html");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment