Items API Methods
on()
Sets up an event listener for the Items API. This method binds a callback function that will be invoked whenever the specified eventName
is fired.
You would want to use this method so that you can take custom actions in your application when certain defined events occur in the assessment player.
The full list of available event names are listed on the Items API Events page.
Examples
function myEventHandler() {
console.log('The callback which executes when an event is fired.');
}
// Sets up a recurring event listener for the 'focused' event.
itemsApp.on('focused', myEventHandler);
// Listen to all assessment player events
itemsApp.on('*', myEventHandler);
Arguments
-
eventName string
Name of the event that you want to listen to.
-
eventCallback function
Callback function that will be triggered whenever the event is fired.
-
context object
Execution context that will be used for
this
when the callback function is fired.
Return value
None (undefined
).
Related articles
- List of all Items API Events
- The
off()
method, the method used to remove custom event listeners from the assessment events. - The
once()
method, the method used to add custom event listeners to the assessment events that will only execute once. - Items API Events live demo