View Full Version : Context Menu Script - want to dynamically modify

11-22-2004, 11:22 AM
Script: Context Menu Script

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?


11-22-2004, 11:28 AM

Should be in your BODY section I.E:

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

rgds,Simonf :cool:

11-22-2004, 12:06 PM
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>
<div class="menuitems" url="mailto:dynamicdrive@yahoo.com">Email Us</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?


11-22-2004, 10:14 PM
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:

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

11-23-2004, 02:38 AM
Terrific, thanks a heap.