Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript If statement

    Hey guys, I am having trouble trying to merge two codes together to give me a basic if statement. So If the user is a mobile user, include header_mobile.php , else include header.php . I am trying to do this to sort out my navigation bar as mobile users can't view my drop down menus on my navigation bar, due to not having the hover function with touchscreens. Here are the two codes I have I just can't seem to merge them , any help would be great!


    Javascript If Statement

    <script type="text/javascript">

    $(function() {
    if( /Android|Mac|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
    $('.mobile').show();
    }else{
    $('.desktop').show();
    }
    });


    </script>


    PHP Include

    <?php include("header.php"); ?>

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,479
    Thanks
    6
    Thanked 981 Times in 954 Posts
    You are mixing JavaScript and PHP. Ideally you should do both on the server side. However, this all is redundant if you would just use one navigation and CSS media queries to apply a different look.

  • #3
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the reply,

    is it possible to maybe not mix the two, but use a javascript code that would include the header.php or does it have to be a PHP function because the header is a php file?



    if( /Android|Mac|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
    *INCLUDE HEADER_MOB.PHP*
    }else{
    *INCLUDE HEADER.PHP

  • #4
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In case anyone was wondering I managed to sort the code by instead of using

    <?php include ("header.php") ?> and the javascript IF statement I used

    <?php
    $ua=$_SERVER['HTTP_USER_AGENT'];
    if(preg_match('/Mobile|Android|webOS|iPhone|iPad|iPod|BlackBerry/',$ua)) include("header_mob.php");
    else (
    include ("header.php"));
    ?>


  •  

    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
    •