Dynamically change URL for popup

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
JeffW
Beginner
Beginner
Posts: 2
Joined: Wed Jan 14, 2004 11:01 pm
Location: New York

Dynamically change URL for popup

Post by JeffW »

I'm using popup to display multiple choices on a link -- actually, on a set of links within a page -- and would like to change the menu URLs based upon the current link. Does anyone know how to do this? I assume the following gets me to the menu object in question but how do I reference the individual items and the URL within each item?

_mn = getMenuByName("mymenu");
_m[_mn]...

Thanks in advance for any advice.
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

Hi Jeff,

You've figured out how to get the "menu number", which you've seen is the index into the menu array (there's actually another step to getting a reference to the object itself). But as you've also seen, that's not really the main issue here. To rephrase what you stated, the main issue is figuring out how to get to the menu item, then how to get to the various properties of that item.

Note: the following is a lengthy explanation because (a) sometimes I'm just long winded and (b) there may be others out there who are interested, and I figured if I explained in detail here, I could just refer to this thread for future seekers of arcane menu stuff.

Internally, everything that you configure in the menu_data.js code ends up in one array or another. _m[] is an array of menus. _mi[][] is an array of menu items; its first dimension is from 0 to the total number of items combined from all of the various menus (minus 1 of course), and its second dimension holds the setting of each menu item property. So, its like this: _mi[item][property], where the second dimension is indexed by the "Code Ref" numbers given in the quick reference table for menu item properties.

Hope that made sense so far... if it did, you'll realize that, in theory, once you know the indexes, it's pretty straight forward to set or get any property for any menu item. In practice, however, it's the "once you know the indexes" part that's tricky. The index to the second dimension is easy... all of them appear in the quick ref table I mentioned earlier. So the hard part is finding the index into _mi[][]'s first dimension, to target the specific menu item(s) you want to change. I could not find a built-in method of doing that (I may have just missed it), so I did it myself. The following function will find the item you specify and change whatever property you want to change:

Code: Select all

function mm_changeItemProperty(menuName, itemName, codeRef, newValue, updateDisplay)
{
  menuName = menuName.toLowerCase();
  for (i=0; i<_mi.length; i++)
    if (_mi[i][1].replace(/\&nbsp\;/ig,' ') == itemName && _m[_mi[i][0]][1] == menuName) break;
  if (i == _mi.length) return;
  _mi[i][codeRef] = newValue;
  if (updateDisplay) BDMenu(_mi[i][0]);
}
This function takes five parameters.

(1) - menuName is the name of the menu containing the item you want to change. This parameter is necessary to differentiate among items containing the same text but in different menus. The menuName is given in the code that creates the menu. It is not case sensitive. For example, if you create a menu with the following code:

Code: Select all

with(milonic=new menuname("Software")){ 
style=menuStyle; 
...other properties and item definitions...
aI("text=Downloads Page;url=downloads.html;");
}

then the name of the menu (its menuName) is given in the first line as 'Software'.

(2) - itemName is the name of the item whose properties you want to change. Since the menu system does not assign an internal item name, I use the text that appears in the menu item itself, and so the itemName is given in the text= property of the aI() function that defines the menu item. It is case sensitive. So, for example, in your 'Main Menu', if you have a 'Downloads Page' item defined like so:

Code: Select all

aI("text=Downloads Page;url=downloads.html;");
then the itemName of this menu item is 'Downloads Page'. We're looking for an exact match here, so remember that it is case sensitive, and leading and trailing spaces also count. Speaking of spaces, when calling the function, substitute a normal space in itemName for any &nbsp; in the text property of the item's aI() definition. For example, if your menu item was defined with one or more non-breaking spaces, like so:

Code: Select all

aI("text=Downloads&nbsp;Page;url=downloads.html;");
then the itemName you pass in the function call would still be 'Downloads Page'.

(3) - codeRef is the index or "code reference" of the property that you want to change. Each menu item property has a unique "code reference" number; these numbers are found in the "Code Ref" column of the quick reference table that lists the menu item properties. For example, the codeRef for an item's offbgcolor property is 7, the codeRef for the item's URL property is 2.

(4) - newValue is the new value that you want to assign to the identified menu item property, for the targeted menu item. This might be a numeric or a string value, depending on what type of property you are changing (a color or URL would be a string, widths would be numeric).

(5) - updateDisplay is a boolean indicating that you do (true) or do not (false) want to force an immediate update for display pruposes. You'd typically want to use true for visual properties, like color or size, especially if the menu is already visible when you make the change. You could use false for "behavioral" properties, like openonclick or the URL, things that won't be used until the next time the item is moused over or clicked (using true for these shouldn't hurt, I think, but would cause an additional, probably unnecessary function call).

So, using the examples above, the starting URL for the "Downloads Page" menu item in the "Software" menu is "downloads.html". Suppose you wanted to change that URL to "trialDownloads.html"... you'd do so like this:

Code: Select all

mm_changeItemProperty('Software','Downloads Page',2,'trialDownloads.html',0);
In your case, you could change URLs in your popups by calling mm_changeItemProperty() from the onmouseover event in the link, before you call popup(). You might even want to wrap the calls to mm_changeItemProperty() and popup() inside of your own function, to simplify the coding for multiple links.

OK... so, like... it's late, you dig? I hope what makes sense to me at 1:50 AM makes sense to you at a more normal hour! I'm clicking the "Submit" button...

Hope that helps,

Kevin
JeffW
Beginner
Beginner
Posts: 2
Joined: Wed Jan 14, 2004 11:01 pm
Location: New York

Post by JeffW »

Kevin: A 5-star reply, just what I needed, many, many thanks.
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

JeffW wrote:...A 5-star reply, just what I needed, many, many thanks.
One star per parameter! You're welcome Jeff. Do me a favor and let me know if it works. I forgot to mention that I had only played with this extensively in IE6/Win2k. Haven't really done much property changing in other browser/os combos.

Kevin
oviroa
Beginner
Beginner
Posts: 3
Joined: Fri Nov 05, 2004 2:11 am

mm_changeItemProperty crashes IE on a MAC

Post by oviroa »

mm_changeItemProperty crashes IE on a MAC. Any idea why?
Bob Martin
Advanced
Advanced
Posts: 26
Joined: Tue Nov 18, 2003 9:54 pm

Post by Bob Martin »

Excellent documentation for most of what I need to do, and it has worked like a champ so far. Now, how do you change a menu's page properties, like bgcolor, after it has been displayed?
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

I think this will not work on a menu, only on items, so you'd use the item number, for whichever bgcolor you want, on or off and use that to make the change. The offbgcolor reference number is 5 and the onbgcolor is 7. You can find the reference numbers for properties in the Menu Quick Reference Guides on the Home Page Menu under DHTML Menu link. They are listed for style, menu and item properties. I think I may have the links below my name. There are also clickbgcolor and clickcolor and I Think a clickclass or image.

Ruth
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

Someone must have been thinking of you :!: As I was searching for something else I found this topic which seems to refer to a function to change menu properties, not just items. Not sure if that is what you need, but since it said modifying menu properties I thought you might want to check it.

Ruth
Post Reply