...

View Full Version : getting addEventListener working in ie.



rlemon
11-13-2006, 08:39 PM
hey everyone.
http://rob.lemon.googlepages.com/rltClickRegistrationModel.html
That is the sample page i'm working with.
i started just registering click events, then when i remembered IE does not support addEventListener i decided it would be 'easier' too just add it in.

And so this code came too be



if (!window.addEventListener)
{
Object.prototype.addEventListener = function(eventName, func, capture)
{
if (window.attachEvent)
{
window.attachEvent('on' + eventName, func);
}
window.addEventListener = Object.prototype.addEventListener;
}


I do not receive an error, but I do not hit the event handler.

any ideas where i've went wrong?

GJay
11-13-2006, 10:18 PM
in that code you're missing a closing }...

rlemon
11-14-2006, 06:04 PM
in that code you're missing a closing }...



if(!document.addEventListener)
{
Object.prototype.addEventListener = function(eN, F)
{
if(this.attachEvent)
{
this.attachEvent('on' + eN, F);
}
}
document.addEventListener = Object.prototype.addEventListener;
}


works now. i had to add the method to the document object instead of window. worked fine after that.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum