Thursday, 12 June 2014

Steps of 301 Redirect For Mobile using JavaScript

Magento Development | Ecommerce Web Development Company
301 Redirection For Mobile Site
 Open homepage for website in a text mode or HTML editor. Put mouse cursor just above the "</head>" tag and press "Enter" key once to create a blank line.
  • Copy below given code in step 2 and paste in to the blank line:
               <script type="text/javascript">
                         if (screen.width <= 699) 
                                  document.location = "filename.html";
  • Replace "filename.html" with the name of mobile web page, relative to website root.
                     document.location = "/m/index.html";
                    document.location = "mobile.html";
Given code will redirect to any device with a screen width below 699 pixels to mobile site.
You may adjust the screen width to 480 if you want to target iPhones & other Smartphones 

         if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) 

Replace "" with the URL to iPhone-optimized website.

No comments:

Post a Comment