Last active
December 23, 2023 10:50
-
-
Save lucmsilva651/e881a09c398388de7fd64190ff0d15da to your computer and use it in GitHub Desktop.
Redirect to another site when mobile device is detected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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