I have been trying to understand why sometimes IE8 doesn\'t like PreventDefault and why sometimes it seems to be OK (no errors). From what I have read, including here at SO
Yes, your understanding sounds correct. Also, if you're using a "DOM0" event handler (e.g. someElement.onclick = function(e) { ... }
), there is a simpler way to prevent the browser default behaviour that works in all browsers that support events: return false
.
var someElement = document.getElementById("someElementId");
someElement.onclick = function(e) {
// Do some stuff
return false;
};
However, in this case, the event is not passed to the event handler in IE <= 8 and you have to get it from window.event
instead.