Results 1 to 3 of 3

Thread: Detect Mobile Platform

  1. #1
    Join Date
    Jul 2009
    Location
    Binus University
    Posts
    472
    Thanks
    78
    Thanked 21 Times in 21 Posts

    Default Detect Mobile Platform

    Hi, i have from in detecting mobile platform. This is i use to redirect the home page, to the mobile version.

    I'm using this script now:
    Code:
    <script type="text/javascript">  
        var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));  
        if (mobile) {  
            document.location = "mobile.html";  
        }  
    </script>
    This is my website then i'm try to implement

    But not it failed. So is there any other script to help me...
    Thanks in advanced.
    _____________________

    David Demetrius // davejob
    _____________________

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I have no mobile device to test on. Which are you using? What's its navigator.userAgent string look like? Does it contain any of the keywords that the regular expression tests for? To find out, use a simple page:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
    </head>
    <body>
    <script type="text/javascript">
    document.write(navigator.userAgent);
    </script>
    </body>
    </html>
    A simulator might not report the the navigator.userAgent. Although it should, all it's technically required to do is to render as that agent. To find out, again one can run the simple test page above.

    Anyways, try this:

    Code:
    <script type="text/javascript">
    if (/android|blackberry|iphone|ipod|mini|palm|series60|symbian|windows ce/i.test(navigator.userAgent)){
    	location.href = "mobile.html";
    }
    </script>
    Oh, and what does this:

    i have from in detecting mobile platform
    mean?
    Last edited by jscheuer1; 09-25-2011 at 09:03 AM. Reason: add test page
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    davelf (09-26-2011)

  4. #3
    Join Date
    Jul 2009
    Location
    Binus University
    Posts
    472
    Thanks
    78
    Thanked 21 Times in 21 Posts

    Default

    Thanks John, i'll try it.
    _____________________

    David Demetrius // davejob
    _____________________

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
  •