Javascript / HTML Standard Question

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

What standard talks ommouseover returning "true" or "false" and how it
affects subsequent processing of the <a> element?

Re: Javascript / HTML Standard Question

TS Moderator wrote:
Quoted text here. Click to load it

sorry, I am talking about something like this: <a
href="/images/image2.jpg" onclick="changeImg(this.href); return false;">

Re: Javascript / HTML Standard Question

Fleeing from the madness of the jungle
and said:

Quoted text here. Click to load it

Can't help you with 'standards' refs - try ... news:comp.lang.javascript=

perhaps the examples here help?

could be issues - that's a very old page.

-- =

William Tasso

Re: Javascript / HTML Standard Question

TS Moderator wrote:
Quoted text here. Click to load it

I'm not sure about "standards," but in my experience, this would mean:

IF the user had JavaScript enabled, when they clicked, the changeImg
function would be run, with the href information passed to the function
("/images/image2.jpg"). The function would do whatever its gonna do. The
"return false" part would keep that mouseclick from actually activating
the link, so the user would not get sent to "/images/image2.jpg" --
unless, of course, the function changeImg sends him.

IF the user does NOT have JavaScript enabled, then clicking the link
would take the user straight to "/images/image2.jpg". The user would not
pass Go, and would not collect $200.

David J. Hennessy / /

Re: Javascript / HTML Standard Question

TS Moderator wrote:

Quoted text here. Click to load it

These are "DOM events", so their general behaviour is described in the
DOM standard.

In particular the concept of "event cancellation" is described in
general terms

It doesn't talk about what happens when you cancel an event, it talks
vaguely about what doesn't happen, and even then it only says that "the
default action no longer happens". It certainly doesn't (correctly) try
to state _what_ this default action would have been. I'm not sure where
you'd even find any definition of what such a default action for a HTML
object would be -- it's even browser dependent, not standards based.

You might also notice that this standard for W3C DOM Level 2 bears
little relation to most live code! It talks about calling a
preventDefault() function to cancel events, when the usual approach is
to return false. This function return approach works fine, and it's the
DOM Level 0 definition put forward by Netscape somewhere back in the
mists of time. I don't have a good reference link for this, it's so
long ago.

In general, returning function values as false is simple and works
fine. The Level 2 approach is better because of another new feature it
added, that of registering multiple event handlers to a single event.
This is very useful when you start looking at window onload and similar
events, where you might have many event handlers all wanting a piece of
the action. It's too awkward to coordinate their function returns, so
the easiest approach is to use the preventDefault() function whenever
you need it (quite possibly more than once).

Site Timeline