We were doing lots of mobile websites lately and was using the below Javascript redirection code but one of our client doesn’t want iPad users redirected to mobile site instead they will access the regular site.
Previous Script – Use this script if you want all mobile users including iPad users redirected to your mobile site.
1 2 3 4 5 6 7 8 9 |
<script language=javascript> var redirectagent = navigator.userAgent.toLowerCase(); var redirect_devices = ['vnd.wap.xhtml+xml', 'sony', 'symbian', 'nokia', 'samsung', 'mobile', 'windows ce', 'epoc', 'opera mini', 'nitro', 'j2me', 'midp-', 'cldc-', 'netfront', 'mot', 'up.browser', 'up.link', 'audiovox', 'blackberry', 'ericsson', 'panasonic', 'philips', 'sanyo', 'sharp', 'sie-', 'portalmmm', 'blazer', 'avantgo', 'danger', 'palm', 'series60', 'palmsource', 'pocketpc', 'smartphone', 'rover', 'ipaq', 'au-mic', 'alcatel', 'ericy', 'vodafone', 'wap1', 'wap2', 'teleca', 'playstation', 'lge', 'lg-', 'iphone', 'android', 'htc', 'dream', 'webos', 'bolt', 'nintendo']; for (var i in redirect_devices) { if (redirectagent.indexOf(redirect_devices[i]) != -1) { location.replace("http://www.yourdomain.com/mobile"); } } </script> |
Current Script – Use this script if you want all mobile users except iPad users redirected to your mobile site.
1 2 3 4 5 6 7 8 9 10 11 12 |
<script language="javascript" type="text/javascript"> if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/Android/i)) || (navigator.userAgent.match(/webOS/i)) || (navigator.userAgent.match(/Opera Mini/i))|| (navigator.userAgent.match(/BlackBerry/i))) { location.href='http://www.yourdomain.com/mobile'; } </script> |
Note: Place the above script within <head> tag.