...

View Full Version : How do I display or hide a Javascript menu based on the current url in a php page?



littlealex2009
07-15-2009, 10:04 AM
How do I display or hide a Javascript menu based on the current url in a php page?

I want to specify when a java menu appears on a page based on the current url - does anyone have a script for the vars and conditional statements to make this happen - it would be something like this in natural language:

<javascript>
if currenturl = http://jemmakidd.com/categories.php
then displaymenu
else if currenturl = http://jemmakidd.com/categories.php?cat=14 (or 15,16 etc)
then DONOTdisplaymenu

What is needed is that, if you look at this page there is a java menu under the first category:

http://jemmakidd.com/categories.php

I WANT the menu to appear on that page so that is working, however if I look at one of the store categories, like on this page, I do NOT want the menu to appear - it may be that this can be done without using a java current url type function - thats why I'm asking...

http://jemmakidd.com/categories.php?cat=14

So to summarise:

http://jemmakidd.com/categories.php (If this url is used DO display menu - if any other url DONT display menu)

Thanks again...any ideas?

littlealex2009
07-15-2009, 10:14 AM
This is the menu code I want to fire IF the url is http://jemmakidd.com/categories.php followed by the html to display the menu...


JAVA



<script type="text/javascript">

//SuckerTree Vertical Menu 1.1 (Nov 8th, 06)
//By Dynamic Drive: http://www.dynamicdrive.com/style/

var menuids=["suckertree1","suckertree2"] //Enter id(s) of SuckerTree UL menus, separated by commas

function buildsubmenus(){
for (var i=0; i<menuids.length; i++){
var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
for (var t=0; t<ultags.length; t++){
ultags[t].parentNode.getElementsByTagName("a")[0].className="subfolderstyle"
if (ultags[t].parentNode.parentNode.id==menuids[i]) //if this is a first level submenu
ultags[t].style.left=ultags[t].parentNode.offsetWidth+"px" //dynamically position first level submenus to be width of main menu item
else //else if this is a sub level submenu (ul)
ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
ultags[t].parentNode.onmouseover=function(){
this.getElementsByTagName("ul")[0].style.display="block"
}
ultags[t].parentNode.onmouseout=function(){
this.getElementsByTagName("ul")[0].style.display="none"
}
}
for (var t=ultags.length-1; t>-1; t--){ //loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
ultags[t].style.visibility="visible"
ultags[t].style.display="none"
}
}
}

if (window.addEventListener)
window.addEventListener("load", buildsubmenus, false)
else if (window.attachEvent)
window.attachEvent("onload", buildsubmenus)

</script>


HTML



<td width="265" valign="top"><div class="suckerdiv">

<div align="left">
<ul id="suckertree1">
<li><a href="#">FACE</a>
<ul>
<li><a href="#">PRIMER</a></li>
<li><a href="#">FOUNDATION</a></li>
<li><a href="#">POWDER</a></li>
<li><a href="#">CONCEALER</a></li>
<li><a href="#">BLUSH</a></li>
<li><a href="#">LUMINISORS</a></li>
</ul>
</li>
<li><a href="#">EYES</a>
<ul>
<li><a href="#">PRIMER</a></li>
<li><a href="#">SHADOW</a></li>
<li><a href="#">MASCARA</a></li>
<li><a href="#">BROW</a></li>
<li><a href="#">LASH</a></li>
<li><a href="#">LINER</a></li>
<li><a href="#">GLOSS</a></li>
</ul>
</li>
<li><a href="#">LIPS</a>
<ul>
<li><a href="#">PRIMER</a></li>
<li><a href="#">LIP CARE</a></li>
<li><a href="#">LIPSTICK</a></li>
<li><a href="#">LIP GLOSS</a></li>
<li><a href="#">LIP PENCIL</a></li>
</ul>
</li>
<li><a href="#">TOOLS</a>
<ul>
<li><a href="#">EYE</a></li>
<li><a href="#">FACE</a></li>
<li><a href="#">LIP</a></li>
<li><a href="#">BAGS/CASES</a></li>
<li><a href="#">LIP PENCIL</a></li>
</ul>
</li>
<li><a href="#">COLLECTIONS</a></li>
<li><a href="#">MULITI-PURPOSE</a></li>
</ul>
</div>
</div>

Philip M
07-15-2009, 10:42 AM
<div id = "theMenu" style="display:block" >The menu in here</div>

<script type="text/javascript">
var nowUrl = location.href;
if (nowUrl != "http://jemmakidd.com/categories.php") {
document.getElementById("theMenu").style.display="none";
}

</script>

This is the JavaScript forum. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names.


Following protracted negotiations we have come to an arrangement with the banks under which we have agreed not to supply goods to our customers on credit. For their part the banks have agreed not to sell fishing equipment.

littlealex2009
07-15-2009, 11:06 AM
Thanks SOOO much Philip - that code worked perfectly and has saved me a real headache!

Just so I know in future - where SHOULD I be posting on this language...?

A :)

Philip M
07-15-2009, 11:17 AM
Javascript = http://www.codingforums.com/forumdisplay.php?f=2

Java = http://www.codingforums.com/forumdisplay.php?f=54

As I say, these are entirely different languages. Like Austrian and Australian :D

littlealex2009
07-15-2009, 12:54 PM
haha - cheers... :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum