"Mark Anderson" <mark@notmeyeardley.demon.co.uk> writes:
[color=blue]
> If there are any well explained (i.e. little assumed knowledge) examples of
> correct use of 'return false' within <a> link events, I'd be very happy if
> you or anyone else could note the URLs[/color]
I don't have an URL available, but the rule is simple:
If you don't return false, the link is followed (as if there was no
onclick handler). If you do return false, the click event is canceled,
and the link is not followed.
You should always return false if you don't mean to follow the link.
What you ran into here was a combination of this and the href="#" link.
It points to the current page, at a non-existing identifier (just as
href="#foo" would point to the element with id="foo"). Since it is the
current page, the browser don't *need* to load it, but some do anyway
(which could probably be correct for dynamic pages). Internet Explorer
doesn't change anything when following href="#", which is why you
could get away with not returning the appropriate false.
Generally, all events are cancelled by returning false from the
handler (if the event can be canceled at all, obviously).
The more modern way of attaching event handlers to elements is the W3C
DOM 2. There, you don't return false. Instead you call the method
preventDefault on the event object. All browsers still support the old
way, and probably will for quite a while, and IE doesn't understand
W3C DOM 2 Events at all.
Returning false is mentioned in some of the FAQ entries:
<URL:http://jibbering.com/faq/#FAQ4_24>
<URL:http://jibbering.com/faq/#FAQ4_27>
/L
--
Lasse Reichstein Nielsen -
lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'