How To Redirect Your Website To Mobile Website On Mobile Devices By Javascript

Hello Friends, Some days ago I was working on one project in which I have to redirect site to its mobile website when it opens in iPhone,iPad,iPod,Blackberry and Android by Javascript.I have searched so many time on internet and lastly found one code which was not working perfectly for all devices. So I have changed some things in that code to make it work for iPhone,iPad,iPod,Blackberry and Android. So i though it to post it on my website, So it would be helpful for my users to make them site redirect to iPhone,iPad,iPod,Blackberry and Android.

So below is Javascript code by which you can redirect your website to mobile website on Mobile Devices.

<script language=javascript>
<!--
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/blackberry/gi)) || (navigator.userAgent.match(/android/gi)))
{
   location.replace("mobile-page.html");
}
-->
</script>

Put this code at top of your website page, So whenever anyone open your site on mobile device it will redirect to mobile-page.html or you can change it to your mobile site address. Let me know if you have any other great code for mobile redirects.