faqts : Computers : Programming : Languages : JavaScript : Links

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

1 of 3 people (33%) answered Yes
Recently 1 of 3 people (33%) answered Yes

Entry

how to retailn "link" color even after giving href = "#" for all links on my page

Jan 9th, 2002 07:41
David Blackledge, Sudhir Tadepalli,


First off, you should really only use the href="#" sparingly.  Whenever 
possible, you should actually have the href go to somewhere useful so 
users with JavaScript disabled don't lose all functionality in your 
page.
To answer your question, you need to make certain that your onclick 
event handler is doing a 
return false;
at the end.  When you do this, the link (whatever it points to) will not 
be followed, thus it will not be considered visited.
However, I believe under some circumstances and in some browsers the 
browser will decide that in fact any href starting with # is already 
visited in the instant that you load the page since all # links are 
links to somewhere in the same page.  Consequently, since you don't want 
an active link anyhow, I would recommend using:
href="javascript:void(0)"
This creates a link that does nothing, and isn't pointing to somewhere 
in the current page.  You should still return false in your onclick 
handler to be certain you never get the "visited" color.
David
http://David.Blackledge.com