SitePoint Sponsor |
|
User Tag List
Results 1 to 2 of 2
-
Mar 25, 2004, 12:08 #1
- Join Date
- Mar 2004
- Location
- Belgrade, Serbia
- Posts
- 4
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Prototype addEventListener for IE?
I wonder is it possible to generally prototype event listeners functions for IE?
Something like...
Code:if ( typeof(HTMLElement) != "undefined" ) { if ( !(HTMLElement.prototype.addEventListener) ) { HTMLElement.prototype.addEventListener = function(sEv,sFn,bCap) { if (this.attachEvent) { this.attachEvent("on" + sEv, sFn); } }; } }
I want to simply write oObj.addEventListener() and that it works in IE too. If that is not too much to ask...
-
Mar 28, 2004, 12:38 #2
- Join Date
- Dec 2002
- Location
- Alabama, USA
- Posts
- 2,560
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I've experimented with similar things. But I use the DOM2 event model less and less. What you're wanting is as simple as this:
element.onclick = myFunction;
One of the many benefits to using the DOM0 event model is that, inside myFunction this points to element. That's not always the case when using addEventListener().
I'm finally starting to realize that the only time anyone should use the DOM2 event model is when they want more than one listener on the same object. And even then, there are other ways - I've experiment with code for this too
Your project sounds very interesting - I'm not trying to talk you out of it, its just that I've been thinking about this lately.
Cross-Browser.com, Home of the X Library
Bookmarks