473,394 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Overriding native HTMLElement.addEventListener

I'm trying to override the native HTMLElement.addEventListener in
firefox so that I can do some extra things. I know it's possible to
add methods to the HTMLElement prototype and for them to be present on
instances of that element, but modifying native methods doesn't seem
to stick ie:

HTMLElement.prototype.addEventListener = function()
{
alert('overridden');
};

HTMLElement.prototype.anotherMethod= function()
{
alert('anothermethod');
};

var div = document.createElement('div');
alert(div.anotherMethod.toString()); // alerts function ()
{ alert('anotherMethod'); }
alert(div.addEventListener.toString()); // alerts function() { [native
code ]};

Does anyone know if its possible to override a native method in
forefox ?

Marc
Jul 23 '08 #1
5 5254
marchaos wrote:
Does anyone know if its possible to override a native method in
[Firefox]?
It is possible, by direct assignment, to ignore the existing method of a
host object (you cannot access objects directly, you can only use references
to them) but it is error-prone always. Forget about it and use a wrapper
method (maybe a property of a user-defined wrapper object) instead.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Jul 23 '08 #2
Cheers.

I guess I will have to resort to something that Prototype does and
have an "observe"
method that wraps addEventListener. I was hoping to keep the W3C API
though :(

On Jul 23, 7:15 pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
marchaos wrote:
Does anyone know if its possible to override a native method in
[Firefox]?

It is possible, by direct assignment, to ignore the existing method of a
host object (you cannot access objects directly, you can only use references
to them) but it is error-prone always. Forget about it and use a wrapper
method (maybe a property of a user-defined wrapper object) instead.

PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Jul 24 '08 #3
Cheers.

I guess I will have to resort to something that Prototype does and
have an "observe"
method that wraps addEventListener. I was hoping to keep the W3C API
though :(

On Jul 23, 7:15 pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
marchaos wrote:
Does anyone know if its possible to override a native method in
[Firefox]?

It is possible, by direct assignment, to ignore the existing method of a
host object (you cannot access objects directly, you can only use references
to them) but it is error-prone always. Forget about it and use a wrapper
method (maybe a property of a user-defined wrapper object) instead.

PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Jul 24 '08 #4
* marchaos wrote in comp.lang.javascript:
>I'm trying to override the native HTMLElement.addEventListener in
firefox so that I can do some extra things. I know it's possible to
add methods to the HTMLElement prototype and for them to be present on
instances of that element, but modifying native methods doesn't seem
to stick ie:
Note that .addEventListener() is not on HTMLElement but on EventTarget
(a different interface that is implemented by all objects that implement
the Element interface). Whether that helps you with your problem I do
not know, I would rather second Thomas' advice.
Jul 30 '08 #5
On Jul 30, 12:35*pm, Bjoern Hoehrmann wrote:
* marchaos wrote in comp.lang.javascript:
<snip>
Note that .addEventListener() is not on HTMLElement but on
EventTarget (a different interface that is implemented by
all objects that implement the Element interface). ...
The DOM Level 2 Events specification says "The EventTarget interface
is implemented by all Nodes in an implementation which supports the
DOM Event Model". So it is objects implementing the Node interface
that should implement the EventTarget.
Jul 30 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jason Keirstead | last post by:
Is there a way I can add a setter/getter to the HTMLElement prototype in internet explorer? This, for example, works fine in Mozilla: HTMLElement.prototype.__defineSetter__("foobar", function...
1
by: Christopher Benson-Manica | last post by:
How do you extend HTMLElement? Why can't you just do HTMLElement.prototype.foo=function() { alert( 'foo' ); } I assume HTMLElement belongs to some kind of namespace, but darn if I can find...
4
by: PJ | last post by:
Is it possible to extend the Node object so that the DOM function addEventListener can be used w/ IE? Does anyone have an example of this? Thanks, Paul
3
by: Jake Barnes | last post by:
37 Signals has built some awesome software with some features I wish I knew how to imitate. When I'm logged into my page (http://lkrubner.backpackit.com/pub/337271) any item that I mouseOver I'm...
10
by: Janus | last post by:
Hi, Is there a way to pass arguments to the callback function used inside an addEventListener? I see that I can only list the name of the callback function. For eg, I use this: var...
1
by: AMDRIT | last post by:
Hello Everyone, We have a production WinForms Application that uses a WebBrowser to display readonly data. In the html document we have SPAN elements that facilitate menu selections. We also...
10
by: r035198x | last post by:
The Object class has five non final methods namely equals, hashCode, toString, clone, and finalize. These were designed to be overridden according to specific general contracts. Other classes that...
3
by: Csaba Gabor | last post by:
In my Firefox 1.5 (on Win XP Pro) a <BR> element's .textContent returns the empty string. I have no idea why they (W3C) construed this to be reasonable, but it was contested, and denied here:...
0
by: wpjoju | last post by:
i have this code which adds an event listener to a newly opened window but it doesn't seem to work in google chrome. the problem is window.addEventListener seem to work in chrome but if you do...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.