How To Mobile Redirect Your Website On Any Mobile Device

Hello Friends, after long time I am writing post. So today I am writing about one new topic in which I will show you how can we redirect our website to mobile website when it opened from any mobile device. I have done this thing already in one of my client website and this code worked properly. This code is in javascript. We can make code in PHP also, but right now I am just writing you code for JavaScript. Might be I will post code in PHP in next post.

So below is the code for mobile redirection to mobile website on any mobile device.

<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://mymobilewebsite.mobi/");
}
}
-->
</script>

So above is the code which you should put at top of your website page, So when your website will  open in any mobile browser, it will redirect you to your mobile website (in above code http://mymobilewebsite.mobi).

Let me know if you have any problem in using this code.

I am PHP freelancer , So Contact me if you are interested to develop  any website.

Subscribe to PHP Freelancer

Enter your email address: