Redirect Mobile Devices using javascript

Oct-23-2014 in Javascript No comments

Nowadays, mobile devices grow the number of people using mobile devices is very large, as a webmaster you need to optimize your website friendly to mobile devices. In this article, I did not mention about website optimization for display on mobile devices, but I’ll show you what is equally important is how to Detect and redirect mobile devices using JavaScript.

Redirect Mobile Devices using javascript

If you have created a mobile version of your website, when people visit your website , you need to detect they are using a mobile device or desktop computer. If someone visits your website on their phone, you need to move to mobile version optimized for your mobile device.

Here I will analyze the information “user-agent” of the browser to know their are visiting your website with what equipment. You place this code in the head page of your main website code. That way when your website is visited, the javascript will see the browser user-agent and redirect to the mobile version.


How to redirect to mobile site?

You need to change “” to your domain. Above code I have created a subdomain call “m” e.g: this above script code will be automatically redirected to when visitor by mobile devices.

Add Your Comment