Thursday , 23 March 2017
Home » JavaScript » Mobile Redirects by Javascript – Redirection code to Mobile Device
Mobile Redirects by Javascript – Redirection code to Mobile Device

Mobile Redirects by Javascript – Redirection code to Mobile Device

Hello Friends,

I am working on a mobile creation website where I need to redirect user to mobile version of site when they are on mobile device. So basically there will be two sites.. One is for Browsers in PC and another is mobile version. If someone opens main website in mobile device than we need to track it and redirect to mobile version of site.

For this, I have a quick and easy solution. I am just taking screen width and if it is less than 600px than it must be mobile device or ipad. so we will redirect it to mobile version of url.

<script type="text/javascript">
<!--
if (screen.width <= 600) {
location.replace = "http://mobile.phpfreelancedevelopers.com";
}
//-->
</script>
 
-- OR --
 
<script type="text/javascript"> 
// <![CDATA[
	if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {
	location.replace = "http://mobile.phpfreelancedevelopers.com";
	} 
// ]]>
</script>

Redirect code to mobile,mobile redirects by javascript, javascript mobile redirects, Redirect User to mobile site javascript, Javascript Code to redirect user to mobile, Track Mobile device and redirection code, Redirect site to mobile version

      
Plugin by: PHP Freelancer

About Rakshit Patel

I am PHP Freelancer, Rakshit Patel working as PHP Programmer India. I have developed this site to share my knowledge, thoughts and experience during the development of projects. We are group of developers working together. If you want to hire us for any PHP related work, you can reach me via Email, Phone or Chat.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Notify me of followup comments via e-mail. You can also subscribe without commenting.