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";
                              }
                //-->
               </script>
  • Replace "filename.html" with the name of mobile web page, relative to website root.
           example:
                     document.location = "/m/index.html";
      
           Or:
                    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))) 
            {
             location.replace("http://www.yoursite.com/iPhone.html");
             }

Replace " http://www.yoursite.com/iPhone.html" with the URL to iPhone-optimized website.

1 comment:

  1. We are one of the best and leading towing company in Portland and our services are available in various location of Oregon. Call us to get more information about charges, services and more.
    Towing Services near Mt St Helens
    Cargo Transport in Portland
    Towing Services in Gresham
    Towing Company in Beaverton
    Tow Truck Company in Clackamas
    Towing Company near Cougar

    ReplyDelete