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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How do I display or hide a Javascript menu based on the current url in a php page?

    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?

  • #2
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Here is the actual java code...

    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

    Code:
    <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

    Code:
    <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>
    Last edited by littlealex2009; 07-15-2009 at 09:19 AM. Reason: add [code] marker

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Code:
    <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.

  • #4
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Confused!

    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

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Javascript = http://www.codingforums.com/javascript-programming/

    Java = http://www.codingforums.com/java-jsp/

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

  • #6
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    haha - cheers...


  •  

    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
    •