Forum Moderators: open
I have been asked to do the following:
The "menu" should provide links to all pages with a <div> tag and not change spatial appearance across all pages. The link to the page the user is on should become inactive.
The menu should be loaded into each page using a JS routine.
I am going bald with this as I am a relatively new scripter.
Help please anyone......
with (document) {
for (var i=0; i<links.length; i++) {
with (links[ i]) { if (href==location.href) disabled = true
}}}
I'm sure someone here can correct the mistakes. (I'm not certain that links is the correct name for the array and disabled=true might have to be replaced by enabled=false.)
Kaled.
I'll see waht I can do, Kaled.
disabled/enabled aren't <a> attributes - and have no functional effect( although, funnily enough, the text does go a light shade of grey).
Myself, I'm a distruster of
with, but this could be under the influence of hearsay. document.location is deprecated, yet I'll be married with grown up kids by the time support ceases for it. I went for the DOM route too, just to be oh-so up to date. (except for getting the href - no need to overdo it).
var anchs = document.getElementsByTagName('a'), link, k=0;
var loc = window.location.href;
while(anch=anchs[k++])
if(anch.href==loc)
anch.removeAttribute('href');
For pre-DOM browser support, document.links is the only (and easier) option, but I can't think how to deactivate a link. delete isn't allowed, and setting href to an empty string won't stop it being a link.