Doug Lerner wrote:
What does the preventDefault() do that setting returnValue to false not do?
The point is that on the web you encounter browsers with different event
models, in the beginning there was no event object having properties or
methods to prevent the default action associated with an event, you
would simply do e.g.
return true;
or
return false;
in the event handler function where for most events returning false
indicated that you don't want the default action (e.g. for link click
following the link) to be executed. Note however that there were a few
events (mousover/out, error) where returning false had the opposite meaning.
IE's event model usually allows doing return true/false as well but (I
think mostly to have an event model that is scriptable with more than
J(ava)Script) they introduced a global window.event property and allow
setting event.returnValue.
The W3C DOM Level 2 Events model additionally introduced the
preventDefault method on event objects to have a consistent and
language/binding independent way to prevent the default action
associated with and event.
While Mozilla and Opera by now support the W3C DOM Level 2 Events model
MSIE has never bothered to implement that.
So the only difference is that where preventDefault is supported you
have consistent way to prevent the default action by calling that method
while doing return true/false or event.returnValue = true/false for most
events prevents the default action with value false but for instance
mouseover/out on links to prevent the default action, showing of the
link href URL in the status bar, you need to return true. That case
however has become less important as most browsers by now can be
configured and might even configured by default do disallow scripts to
change the status bar message.
--
Martin Honnen
http://JavaScript.FAQTs.com/