Results 1 to 5 of 5

Thread: Context Menu Script - want to dynamically modify

  1. #1
    Join Date
    Nov 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Context Menu Script - want to dynamically modify

    Script: Context Menu Script
    http://www.dynamicdrive.com/dynamici...ontextmenu.htm

    I have incorporated this script into other code, and it works fine. Now I would like to be able to dynamically modify individual entries in the menu, but I can't find a way of doing so. I can do things like

    var menuobj=document.getElementById("ie5menu")
    var menuobjelements=menuobj.getElementsByTagName("div");
    var menuline4=menuobjelements[3]; //This gets me the Message Forum entry

    I can go further down to childnodes and values etc, but they do not seem to give me access to the two things that I want to change - the URL and the Menu Text

    I hope this is clear. Can anyone help, please?

    Thanks,

  2. #2
    Join Date
    Sep 2004
    Location
    Little Falls, Roodepoort, South Africa
    Posts
    421
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    Hi

    Should be in your BODY section I.E:

    <div class="menuitems" url="http://yoursite.com">What you want it called</div>

    rgds,Simonf

  3. #3
    Join Date
    Nov 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks Simonf, that was quick. But maybe I didn't make myself clear, or maybe I don't properly inderstand your reply - In the original code the menu is defined in the BODY section as


    <div id="ie5menu" class="skin0" onMouseover="highlightie5(event)" onMouseout="lowlightie5(event)" onClick="jumptoie5(event)" display:none>
    <div class="menuitems" color="green" url="http://dynamicdrive.com">Dynamicdrive.com</div>
    <div class="menuitems" url="http://dynamicdrive.com/new.htm" target="newwin">What's New?</div>
    <div class="menuitems" url="http://dynamicdrive.com/hot.htm">What's Hot?</div>
    <div class="menuitems" url="http://wsabstract.com/cgi-bin/Ultimate.cgi">Message Forum</div>
    <div class="menuitems" url="http://dynamicdrive.com/faqs.htm">FAQs</div>
    <div class="menuitems" url="http://dynamicdrive.com/submitscript.htm">Submit</div>
    <hr>
    <div class="menuitems" url="mailto:dynamicdrive@yahoo.com">Email Us</div>
    </div>

    Sure, I can modify any of those entries in my source file. But what I want to do is to change one of the menu entries from within my script. So that if one part of my script has been executed, right-clicking to bring up the menu will show certain entries, but after another part of my script has executed, then invoking the menu would show slightly different entries.

    I don't want to have multiple sets of menu definitions, I just want to manipulate the entries in a single definition.

    I think I'm getting on track... do I want .setAttributes?

    Thanks

  4. #4
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    You're basically there already. Here's a sample function that collects all the submenus within the context menu, and changes the first entry's text and URL when run:

    Code:
    function changeitem(){
    var maindiv=document.getElementById("ie5menu")
    submenus=maindiv.getElementsByTagName("DIV")
    submenus[0].setAttribute("url", "http://www.google.com")
    submenus[0].innerHTML="Google"
    }

  5. #5
    Join Date
    Nov 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Terrific, thanks a heap.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •