A script to restrict site only to ipad

Discussion in 'JavaScript' started by kojinmax, Jan 24, 2012.

  1. #1
    I need a script that only allow users with an Ipad to view my site. I need it to display a message saying the browser is not compatible and this site needs to be viewed with your Ipad. I am a total newbee at these forums and programming so go easy on me.
     
    kojinmax, Jan 24, 2012 IP
  2. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #2
    try this..

    
    
    if(!/iPad/i.test(navigator.userAgent))
    {
       alert("Sorry, this site can only be viewed by in iPad.");
       window.location = 'http://www.google.com/'; // redirect them some where
    }
    
    
    Code (markup):
     
    JohnnySchultz, Jan 25, 2012 IP
  3. kojinmax

    kojinmax Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Is that going in my header.php or index.php file. I'm using a wordpress template. I added it in but it just displays the code you gave. I know for sure I'm doing it wrong and your code works.
    <?php
    /**
    * @package WordPress
    * @subpackage Default_Theme
    */
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>

    <head profile="http://gmpg.org/xfn/11">

    if(!/iPad/i.test(navigator.userAgent))
    {
    alert("Sorry, this site can only be viewed by in iPad.");
    window.location = 'http://www.mysite.com/'; // redirect them some where
    }
     
    kojinmax, Jan 25, 2012 IP
  4. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #4
    it javascript, you can put it before </head>


    here's the exact code..


    
    <script type="text/javascript">
    if(!/iPad/i.test(navigator.userAgent))
    {
       alert("Sorry, this site can only be viewed by in iPad.");
       window.location = 'http://www.google.com/'; // redirect them some where
    }
    </script>
    
    HTML:
     
    JohnnySchultz, Jan 30, 2012 IP