I have a number of "common" menu items that are displayed on all pages at various directory levels. I would like to disable or modify menu items based on the page being viewed. Can anyone suggest an easyway of doing this?
Thanks
Jim
Disable or Modify Menu items based on page being viewed
-
- Beginner
- Posts: 4
- Joined: Mon Sep 15, 2003 5:51 pm
- Location: Ottawa, Canada
- Contact:
I use this technique very often...
Put these two statements near the top of the menu_data.js file.
Check the file where appropriate. This logic enables the menu item for a specific page, but you just have to change the If statement to suit your application.
If you want to check for all files that start with a particular string, eg. prod*, try this:
Put these two statements near the top of the menu_data.js file.
Code: Select all
var dir = location.href.substring(0,location.href.lastIndexOf('/')+1);
var thefile = location.href.substring(dir.length,location.href.length+1);
Code: Select all
if (thefile == "about.html") {
aI("text=Conditional Page;url=whatever.html");
}
Code: Select all
if (thefile.substring(0,"prod".length) == "prod") {
aI("text=Conditional Page;url=whatever.html");
}
Hi Jim,
Twisted6's ideas are very useful if you want to conditionally include or exclude a menu item in a menu. In other words, by wrapping the call to aI() inside of an "if", the menu item defined by that aI() call will appear in the menu if the condition is met, but will not appear at all in the menu if the condition is not met.
Extending Twisted6's approach, you could always include an item in a menu, but have it appear to be enabled or disabled depending on the conditional test. (You could make an item appear to be disabled by altering the oncolor, onbgcolor, etc... there's even a type=disabled item property that you might find useful). In other words, you could add an "else" to the condition:
Finally, if you want to be able to modify a menu item's appearance and behavior programatically, after the page has been rendered, you can do so with a function called mm_changeItemProperty(), which is described in detail in this post.
Cheers,
Kevin
jshep@magma.ca wrote:...I would like to disable or modify menu items based on the page being viewed...
Twisted6's ideas are very useful if you want to conditionally include or exclude a menu item in a menu. In other words, by wrapping the call to aI() inside of an "if", the menu item defined by that aI() call will appear in the menu if the condition is met, but will not appear at all in the menu if the condition is not met.
Extending Twisted6's approach, you could always include an item in a menu, but have it appear to be enabled or disabled depending on the conditional test. (You could make an item appear to be disabled by altering the oncolor, onbgcolor, etc... there's even a type=disabled item property that you might find useful). In other words, you could add an "else" to the condition:
Code: Select all
if (condition is met) {
aI("..."); // menu item with enabled appearance and behavior
}
else {
aI("..."); // menu item with disabled appearance and behavior.
}
Cheers,
Kevin