Forum Moderators: open
<a href="" onclick="javascript:doBlahBlah()">
----- From MSDN site -----
If HREF is present but is blank (in other words HREF="" OR HREF=), executing the link could possibly display the directory containing the current page, or it could generate an error depending on other elements on the web page and the server environment.
--------------------------
<a href="BlahBlah" onclick="javascript:doBlahBlah(); return false;">
The "return false;" tells the browser (in effect) "oh, nevermind, the user didn't really click the link." Your onclick will still fire correctly though. :)
The only real advantage this would have over just using a "#" as the href is that when the link is clicked it will not append a "#" to the URL displayed to the user in the URL bar.
Jordan
[edited by: korkus2000 at 5:57 pm (utc) on July 29, 2003]
[edit reason] No Sigs Please [/edit]
BTW onClick is an event handler, so you should not include the 'javascript:' pseudo-protocol.
what does[typo] it mean exactly? I think the browser is smart enough to ignore it, but I thought it would be a better practise to put javascript in front. Can someone clarify?
Thanks!
<script> tag with a proper type attribute. You are correct in thinking that it doesn't hurt anything to have it in there, though, it just isn't necessary. :) Jordan
[edited by: korkus2000 at 5:57 pm (utc) on July 29, 2003]
[edit reason] No Sigs Please [/edit]
The only real advantage this would have over just using a "#" as the href is that when the link is clicked it will not append a "#" to the URL displayed to the user in the URL bar.
Actually, there's a big advantage in that people who have JavaScript turned off can still follow the link, presuming you've put a real path in the HREF. And I think I've read in these forums that this method also allows search engine spiders to follow the links. Right?
Interesting! Never even though of that aspect of the problem. So I guess pragmatically and asthetically, including a valid path in the href and then canceling the click event is the best way to go about solving it. Mabye use the base href as the link href if it is otherwise unneeded?
Jordan
[edited by: korkus2000 at 5:57 pm (utc) on July 29, 2003]
[edit reason] No Sigs Please [/edit]
This means the link does not move you from the location where you are at the present and text 'Example' appears as a link.
To go more advanced you could do things like change the cursor style so it does not change i.e.
Now when you move the mouse ove the text 'Example' it appears as a link but the mouse cursor stays the same as well! I hope this helps you.
Bon Bon
[edited by: korkus2000 at 1:59 pm (utc) on Oct. 18, 2003]