
Solid, safe website tools.
Whatever your need, Will Bontrager builds powerful software solutions.
|
(Get Attention Ticker for your web site)
How to Make a Link that Does NothingBy Will Bontrager When an anchor tag is used only for JavaScript functionality, an href attribute is still required. It's a link, after all. This post shows how to keep the browser from visibly reacting when the link is clicked the browser won't go anywhere, won't reload the page, nothing. Putting this attribute into the anchor tag will solve most requirements. If an onclick attribute is already being used in the anchor tag, appending "; return false" (without the quotes) to the attribute's value might work. Appending the return value is required because only one onclick attribute may be present in any one anchor tag. However, if an onclick attribute is already being used and appending "; return false" to the attribute's value does not work (if it must return the true, for example, or the return value is determined by a function call), then the href attribute's value might be changed to something like this: The above is not very elegant, but it works with all browsers I've tested (Firefox, IE, Opera, Netscape 7+, all on XP). To keep non-JavaScript browsers from following a link, the href attribute's value can be replaced with the "not very elegant" solution above (tested only with Firefox on XP) or replaced with an octothorpe character. The above will cause some non-JavaScript browsers to reload the page when the link is clicked. Others will just ignore the link. July 19, 2006 Please note: Articles on this website are presented "as is". However - If you have a question about a CGI script, HTML, CSS, PHP, or JavaScript
Rate this blog post.
No page reload! |
|
|
© 1998-2001 William and Mari Bontrager |
|