dcsan
dcsan

Reputation: 12275

How to remove an EventListener that someone else created?

A library (famo.us) i'm using inserts an event listener into the window that breaks scrollviews. For various pipeline reasons its difficult to modify the library so is there a way to remove an event listener that some other code added?

My understanding is that i need access to the actual function definition when calling the remove call also.

I tried as below, to get the handler reference and then remove it, but without luck.

> getEventListeners(window).touchmove
[
Object
listener: function (event) {
remove: function ()
type: "touchmove"
useCapture: true
__proto__: Object
]

> f=getEventListeners(window).touchmove
[
Object
]

> window.removeEventListener('touchmove', f)
undefined

> getEventListeners(window)
Object {message: Array[1], load: Array[2], unload: Array[1], online: Array[1], resize: Array[1]…}
load: Array[2]
message: Array[1]
online: Array[1]
popstate: Array[1]
resize: Array[1]
touchmove: Array[1]     <<< bugger is still there!
unload: Array[1]

Upvotes: 2

Views: 208

Answers (0)

Related Questions