www.webdeveloper.com
Results 1 to 4 of 4

Thread: detect native/stock Android browser User Agent string via PHP

  1. #1
    Join Date
    Apr 2006
    Posts
    245

    detect native/stock Android browser User Agent string via PHP

    I am getting a lot of JavaScript errors on the native/stock Android 4.1 browser only and I would like to detect the User Agent string via PHP.

    I use the Mobile_Detect library to check for OS, devices and browsers, however it does not support detecting the native Android browser.

    There are numerous posts on SO regarding this topic, but not answer it would seem.

    I am getting a lot of errors stating:

    Code:
    Cannot set property 'webkitTransitionDelay'
    Cannot set property 'webkitTransform'
    ...so I would like to switch jQuery Mobile page transitions off for this browser - but I need to have the ability to detect it first.

    Is there a way to detect it? I must stress it's not the OS I want to detect, it's the native browser (also called Android).

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,246
    You can look at $_SERVER['HTTP_USER_AGENT'] and to some pattern-matching against it.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Apr 2006
    Posts
    245
    Quote Originally Posted by NogDog View Post
    You can look at $_SERVER['HTTP_USER_AGENT'] and to some pattern-matching against it.
    One of the problems I have is that I don't actually know the pattern i'm looking for. I could quite easily do a preg_match on the User Agent string if I knew what the UA string was for the Android Native browser, but I would say that the Android documentation is just as bad as Apple's - non-existant!

    I was hoping there would be a "Android Native" or something similar in the UA, but from what i've found online it seems to be "Android" - which could be the OS or it could be the browser. So not much use there, really.

  4. #4
    Join Date
    Jan 2009
    Posts
    3,346
    Maybe a better solution is more defensive javascript coding. You could check for the existence of the attribute prior to altering it and thus be ready for other browsers you may not be testing for to add or remove that attribute in the future.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles