views:

762

answers:

3

I have been searching for this for some time, but haven't got any explanation.

For "onclick" and other events in javascript, the event handler returning false means "prevent default action". However, there is one exception for "onmouseover". For "onmouseover", returning true means "prevent default action".

Why is there such a weird exceptional case for "onmouseover"?

+6  A: 

Instead of using return false / true to prevent default event behaviour, use the default method / attribute on the event object:

elem.onmouseover = function(e) {
    if (!e) var e = window.event; // IE
    if(e.preventDefault) {
        e.preventDefault();
    } else {
        e.returnValue = false; // IE
    }
}
Luca Matteis
+1  A: 

Who knows why really. Just the way it is: you return TRUE from onmouseover to prevent url from appearing in the status bar, which would be the default behaviour indeed.

Scott Evernden
+1  A: 

As far as I know, returning true to prevent the url of a link to show up in the status bar is an IE-specific (mis-)feature. And trying to understand why IE does things the way it does is often a lost cause - just live with it...

Christoph