Skip to content

HTMLElement.onWindowMigrated method

HTMLElement › onWindowMigrated

Official

Adds an event listener to the element when it is migrated to another window.

Signature:

onWindowMigrated(this: HTMLElement, listener: (win: Window) => unknown): () => void

Parameters:

Parameter Type Description
this HTMLElement
listener (win: Window) => unknown the callback to call when this node has been migrated to another window.

Returns: () => voiddestroy - a function to remove the event handler to avoid memory leaks.

Example:

document.body.onWindowMigrated((win) => {
console.log('window migrated');
});