How Do You Tell Browser to Run Particular Script Only On Iphone/Ipad??

Discussion in 'HTML & Website Design' started by larssonk22, Jan 11, 2012.

  1. #1
    Hi, I using a script to make my site viewable on touch screens, the site works perfectly on all browser expect IE9.
    I want to make sure the script is only loaded if visitor is using an iphone or ipad.

    thanks
     
    larssonk22, Jan 11, 2012 IP
  2. knewedge

    knewedge Active Member

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    61
    #2
    in_array("ipad",$_SERVER[http_user_agent]);
     
    knewedge, Jan 11, 2012 IP
  3. larssonk22

    larssonk22 Well-Known Member

    Messages:
    236
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #3
    Hi thank you for the reply, not sure where I should insert it to my header. I notice you only have "ipad", is that sufficient to also include iphone?

    This is what I would like to tell iphones/ipads to run

    <script type="text/javascript" src="script/iscroll.js"></script>
    <script type="text/javascript">
    var myScroll;
    function loaded() {
    setTimeout(function () {
    	myScroll = new iScroll('scroll-pane', { zoom: true, snap:true, hScrollbar: false, vScrollbar: false, zoomMax: 2, momentum: true });
         }, 100);  
    }
    window.addEventListener('load', loaded, false);
    </script>
    PHP:
    thanks
     
    Last edited: Jan 12, 2012
    larssonk22, Jan 12, 2012 IP
  4. knewedge

    knewedge Active Member

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    61
    #4
    <?php
    $agent = array('ipad', 'iphone');
    foreach($agent as $ary){
    if(in_array($ary, $_server[http_user_agent])){
    //this is a iphone or ipad
    }
    }
    ?>

    Hard to write code on a tablet, syntax might be off, but should give you a good idea.
     
    knewedge, Jan 12, 2012 IP
  5. larssonk22

    larssonk22 Well-Known Member

    Messages:
    236
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #5
    larssonk22, Jan 13, 2012 IP