This is purely a puzzling curiosity.
I know that Opera supports IE's advanced event model (attachEvent
), but why does document.attachEvent
evaluate to false in this browser?
For the same reason as document.all
has a stealthy existence everywhere except IE: to support sites that unconditionally use it, but to avoid going down legacy IE-only codepaths on websites which check it conditionally (which often use other non-standard IE things that aren't supported). This was introduced in 11.62, announced here; it seems noteworthy that detachEvent
and window.event
are also hidden.
As for why Opera does this and others don't: Opera historically supported it without hiding it, and while it was seen as desirable to remove it entirely, the legacy of Opera supporting it was too much to make that feasible, breaking code such as:
function _aspxAttachEventToElement(element, eventName, func) {
if(__aspxNetscapeFamily || __aspxWebKitFamily)
element.addEventListener(eventName, func, true);
else { if(eventName.toLowerCase().indexOf("on") != 0) eventName = "on" + eventName; element.attachEvent(eventName, func); }
}
(From DevExpress.)
if (d.opera)
d.attachEvent("onmousewheel", j);
else
d.onmousewheel = h.onmousewheel = j;
(From krpano.)