Back to Publisher API Reference
pbjs.offEvent(eventType, handler, id)
Turns off an event callback defined with onEvent
Kind: static method of pbjs
Args: eventType, callbackFunction, id
Returns: none
See the getEvents function for the full list of eventTypes supported.
Causes PBJS to search through registered event callbacks and remove the supplied callbackFunction for the specifc eventType.
The optional id
parameter provides more finely-grained event
callback de-registration. This makes it possible to de-register callback
events for a specific item in the event context.
Example
/* This handler will be called only for rightAdUnit */
/* Uses the `pbjs.offEvent` method to remove the handler once it has been called */
var bidWonHandler = function bidWonHandler() {
console.log('bidWonHandler: ', arguments);
pbjs.offEvent('bidWon', bidWonHandler, rightAdUnit);
};
var rightAdUnit="/111111/right";
pbjs.que.push(function () {
var adUnits = [{
code: rightAdUnit,
// ...
},{
// ...
}];
pbjs.addAdUnits(adUnits);
pbjs.requestBids({
//...
});
/* Register a callback for just the rightSlot `bidWon` event */
/* Note that defining an event that uses the 3rd parameter must come after initiating the auction */
pbjs.onEvent('bidWon', bidWonHandler, rightAdUnit);
});