Hide JS Script if iPhone

Discussion in 'PHP' started by craigedmonds, Nov 2, 2010.

  1. #1
    I have a web site that uses a popup using js but on iphones, its impossible to close the pop up.

    So I need some php so that when someone visits the site on an iphone, the script executing the popup will be hidden.
     
    craigedmonds, Nov 2, 2010 IP
  2. bencummins

    bencummins Peon

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Something like this should be able to do it

    < ?php
    $browser = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
    if ($browser == false) { echo 'Code You Want To Execute'; }
    ?>
     
    bencummins, Nov 2, 2010 IP
  3. S1M

    S1M Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Put your popup code in a js function and test before you run it:
    if ( (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) ) { return; }
     
    S1M, Nov 2, 2010 IP
  4. craigedmonds

    craigedmonds Notable Member

    Messages:
    706
    Likes Received:
    135
    Best Answers:
    0
    Trophy Points:
    235
    #4
    Thanks for your help guys.

    I looked around also and in the end I made it like this to cover my bases.

    <?php
    //hide aweber from iphone, ipad and ipod
    $isiphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
    $isipad = strpos($_SERVER['HTTP_USER_AGENT'],'iPad');
    $isipod = strpos($_SERVER['HTTP_USER_AGENT'],'iPod');
    if ($isiphone == false || $isipad == false || $isipod == false) { 
    echo '<script type="text/javascript" src="my aweber url"></script>'; 
    } 
    ?>
    PHP:
     
    craigedmonds, Nov 3, 2010 IP