Skip to content

Instantly share code, notes, and snippets.

@lucmsilva651
Last active December 23, 2023 10:50
Show Gist options
  • Select an option

  • Save lucmsilva651/e881a09c398388de7fd64190ff0d15da to your computer and use it in GitHub Desktop.

Select an option

Save lucmsilva651/e881a09c398388de7fd64190ff0d15da to your computer and use it in GitHub Desktop.
Redirect to another site when mobile device is detected
var userAgent = navigator.userAgent.toLowerCase();
var devices = new Array('nokia','iphone','blackberry','sony','lg','htc_tattoo','samsung','symbian','SymbianOS','elaine','palm','series60','windows ce','android','obigo','netfront','openwave','mobilexplorer','operamini');
var url_redirect = 'http://www.example.com';
function mobiDetect(userAgent, devices) {
for(var i = 0; i < devices.length; i++) {
if (userAgent.search(devices[i]) > 0) {
return true;
}
}
return false;
}
if (mobiDetect(userAgent, devices)) {
window.location.href = url_redirect;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment