0

I'm using projekktor for streaming my videos on browsers. I have many listeners attached on the event state.

video.addListener('state', listener1);
video.addListener('state', listener2);
video.addListener('state', listener3);

Inside the function listener3 and when state === 'COMPLETED' I need to remove the listener listener3. The thing is that to remove a listener you need the variable video. Given that listener3 is a callback, How do I pass the variable video to the function listener3?

JDB
  • 25,172
  • 5
  • 72
  • 123
smarber
  • 4,829
  • 7
  • 37
  • 78
  • The answer will completely depend on how and where listener3 is defined relative to the addListener invocation. – JDB Jan 22 '15 at 18:23
  • This works like a charm! http://stackoverflow.com/questions/939032/jquery-pass-more-parameters-into-callback#answer-939206 – smarber Jan 22 '15 at 18:32

1 Answers1

-1

To remove an event listener in JavaScript use:

Modern browser's:

video.removeEventListener('name', fnName);

Older ie:

video.detachEvent('name', fnName);

DOM level 0:

video['on' + name] = null;

jQuery:

video.off('name');
Millzie
  • 312
  • 1
  • 3
  • 13
  • Look at the bold part of the question: "*How do I pass the variable video to the function listener3?*" You've not answered the question. – JDB Jan 22 '15 at 18:24
  • First I'm very sorry been a long day and im very tierd must have zoomed past it :) ... And Second i'm pretty sure you could use **listener3(video);** – Millzie Jan 22 '15 at 18:30
  • `addListener ` takes two parameters: a string and a reference to a function. `addListener( 'state', listener3(video) )` would pass, not the function, but the result of the function. That's not what the OP was looking for. – JDB Jan 22 '15 at 19:29