With advancement in mobile technology, WAP, EDGE and GPRS technology global number of mobile Internet users is increasing daily. So it’s a good idea to make a mobile version of websites. Usually mobile browsers are different from PC browser so making two different sites, one for PC and one for Mobile is necessary as mobile browser cannot show contents made for PC browsers correctly.

So after you make a mobile version of your site it’s important to redirect your visitors to your mobile site if they open your site from a mobile browser. That’s what we are going to learn here.

So the basic idea is the mobile browsers usually have display of less resolution compared to PC. So if we find out the screen resolution or height or width of display we can redirect the visitors having less screen size to our mobile site.

Below is a JavaScript code to do the job. You need to place the code some where in the head tag of your website or some where between <head> and </head>
It will find out the width of display of the device and redirect visitors to another website if the screen width is less. I have set the width in the code as 600 pixels or the code will redirect visitors having screen width less than 600 pixels to your mobile site. you can increase or decrease the width according to your need. And don’t forget to replace yourmobilesite.com with the URL of your mobile site.

The code::

<script type="text/javascript">
if(screen.width < 600){
window.location = "http://yourmobilesite.com";

Popular Searches: