Being more precise, it did not work in Opera on KDE. What
does work, in Opera on KDE is:
<body onselectstart='return false' onmousedown='return false'>
What did not work, in Opera on KDE, was the seemingly
identical JS:
document.body.onselectstart='return false';
document.body.onmousedown='return false';
The "on..." properties of elements are expecting to be assigned
references to function objects. A few browsers might react to a string
value being assigned to those properties by converting the string into
a function but many will not, so it is defiantly not something you
should ever do if you want a cross-browser outcome.
A possible source of confusion in this area is the way browsers handle
the values of the intrinsic event attributes in the mark-up. They use
those as the source code for the body of functions they create
themselves internally, so given " <body onmousedown='return false'>"
the browser takes the "return false" and uses it as the body of a
function that it creates and assigns to the - onmousedown - property
of the corresponding element in the DOM. The equivilent of a
javascript program performing:-
document.body.onmousedown = function(event){
return false
};
(except that IE will not include the - event - parameter in the
functions it creates (and Chrome exposes the scope chain augmentation
mechanism it uses for these functions)).
This can be illustrated by using intrinsic event attributes in HTML
and then examining the corresponding properties of the DOM elements
with scripts. I.E.:-
<html>
<head>
<title></title>
</head>
<body>
<input type="button" value="test" onclick="alert(this.onclick);">
</body>
</html>
- where clicking the button shows the value of the element's - onclick
- property as type-converted into a string, which clearly shows that
the value is a function object (with a body that corresponds with the
attribute value from the mark-up), and as no javascript code created
that function object the browser must have done so itself.
I don't think that Opera browsers support the - selectstart - events
(they certainly did not used to) so I suppose you are saying that
cancelling the default action of a mosuedown event is effective at
preventing selections, which seems reasonable.