SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2013
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Detect Mobile Browsers

    I am using this code to launch a popup form for people to contact us

    Code:
    <a id="pinfo" class="ajax pullup cboxElement" href="#contact-form">
          Enquiries
        </a>
    However this popup form doesn't behave nicely on mobile browsers.

    I was wondering if I could use some PHP code to detect mobile browsers and point to an e-mail address link instead of the popup form.

    many thanks
    Andy

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,832
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    There is no PHP to accurately detect mobile browsers because the PHP runs on the server before anything is even sent to the device.

    JavaScript can detect mobile devices by testing the screen size.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2013
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Stephen,

    So i suppose i can use javascript to change: href="#contact-form" to href="mailto:example@domain.com"

    ?

  4. #4
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,878
    Mentioned
    47 Post(s)
    Tagged
    0 Thread(s)
    Take a look at this: https://deviceatlas.com/

    I have used this in the past with great success. It works pretty well.

    Else you could write you own one in PHP that checks the user-agent header to decide based on that


Tags for this Thread

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
  •