Skip to main content
addEventListener - Events - Web documentation
function addEventListener
addEventListener<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. ```ts addEventListener('unload', () => { console.log('All finished!'); }); ... dispatchEvent(new Event('unload')); ```

Type Parameters

K extends keyof WindowEventMap

Parameters

type: K
listener: (
this: Window,
) => any
optional
options: boolean | AddEventListenerOptions

Return Type

void
addEventListener(
type: string,
options?: boolean | AddEventListenerOptions,
): void

Parameters

type: string
optional
options: boolean | AddEventListenerOptions

Return Type

void