Skip to content
Advertisement

Remove custom event listener

I’m listening to a custom event:

evt = new CustomEvent("fileThisEmail", {
  detail: {
    name: name,
    email: email,
    content: content
  }
});

window.dispatchEvent(evt);


window.addEventListener("fileThisEmail", this.handleFileEmail);

I need to remove the listener. I’ve tried:

window.removeEventListener("fileThisEmail", this.handleFileEmail);
window.removeEventListener("fileThisEmail");

but neither work. What am I doing wrong?

Advertisement

Answer

The third argument to removeEventListener is mandatory. try this:

window.removeEventListener("fileThisEmail", this.handleFileEmail, false);
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement