Advanced Search

Results 1 to 4 of 4

Thread: script to detect mobile or smaller screen

  1. #1
    Join Date
    Dec 2011
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default script to detect mobile or smaller screen

    I am trying to put a script into the head of my site and have it automatically detect a mobile or screen size from the browser and redirect to a mobile friendly page.

    I am using
    Code:
    <script type="text/javascript"> 
    if(screen.width < 600){ 
    window.location = "http://www.sigl.ws/Phone_Page.html"; 
    } 
    </script>
    I built a small test site to try it out at www.sigl.ws. It is nothing fancy and not a real site. It is strictly to test this script. The main page shows a laptop and the only two buttons that work are home and phone to see what the mobile page would look like.

    I cannot get it work with my android. What am I doing wrong?

    Thanks

    Edited----

    I did try another script and it redirects great. Besides now building a smaller page to view, a new issue popped up on how to allow a mobile user view the main site without getting caught in a loop. I would also like to do this without a duplicate home page. The script I used was:

    Code:
         <script type="text/javascript">// <![CDATA[  
            var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));  
            if (mobile) {  
                document.location = "http://www.mysitename.com/Phone_Page.html";  
            }  
        // ]]></script>
    Thoughts?
    Last edited by BillTheBuilder; 03-13-2012 at 07:08 PM. Reason: removed link

  2. #2
    Join Date
    Mar 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    And maybe this might help you understand..


    detectmobilebrowsers.com

  3. #3
    Join Date
    Dec 2011
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the link.

    I now have the loop taken care of. I am not really versed on CSS yet and so built a small site sized for an android phone for the mobile user to land on, but not kindles or ipads and be able to get back to the main site.

  4. #4
    Join Date
    Feb 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    BilltheBuilder, I am using the same redirect code as you but I'm having a terrible time with the loop part. Can you please post the code you used?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •