It is common knowl开发者_Python百科edge that Internet explorer does not support event passing to event handler functions like this one:
function clickHandler(e) {
// e is undefined in IE
e = e || window.event;
{
For my surprise today, I found out that actually it does. I forgot to do this "e = e || window.event" trick in one of my functions, but it was working in IE8!
I did some tests with IE developer tools, the e object was fully defined and it was so even in IE7 mode.
My question is, should I drop the window.event stuff entirely since I do not care for IE versions prior to 8?
If you assign an event handler using the DOM0 property way, then you still need the e = e || window.event;
bit and you'll get an error if you try and access a property of e
:
document.onclick = function(e) {
e.cancelBubble = true; // Error
};
If you use attachEvent
then you're right, the event parameter is provided to the listener function:
document.attachEvent("onclick", function(e) {
e.cancelBubble = true; // No error
});
精彩评论