Skip to main content

addEventListener

function addEventListener
Jump to headingaddEventListener<K extends keyof WindowEventMap>(
type: K,
listener: (
this: Window,
) => any
,
options?: boolean | AddEventListenerOptions,
): void

Registers an event listener in the global scope, which will be called synchronously whenever the event type is dispatched.

addEventListener('unload', () => { console.log('All finished!'); });
...
dispatchEvent(new Event('unload'));

Type Parameters Jump to heading

Parameters Jump to heading

Jump to headinglistener: (
this: Window,
) => any
optional
Jump to headingoptions: boolean | AddEventListenerOptions

Return Type Jump to heading

void
Jump to headingaddEventListener(
type: string,
options?: boolean | AddEventListenerOptions,
): void
Back to top