Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-04-2013, 10:36 AM   PM User | #1
NafaB
New to the CF scene

 
Join Date: Mar 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
NafaB is an unknown quantity at this point
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"); ?>
NafaB is offline   Reply With Quote
Old 03-04-2013, 11:04 AM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,602
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
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.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 03-04-2013, 11:16 AM   PM User | #3
NafaB
New to the CF scene

 
Join Date: Mar 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
NafaB is an unknown quantity at this point
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
NafaB is offline   Reply With Quote
Old 03-04-2013, 04:00 PM   PM User | #4
NafaB
New to the CF scene

 
Join Date: Mar 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
NafaB is an unknown quantity at this point
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"));
?>
NafaB is offline   Reply With Quote
Reply

Bookmarks

Tags
html, javascript, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:54 PM.


Advertisement
Log in to turn off these ads.