W3cubDocs

/Web APIs

CloseWatcher: close event

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

A close event is fired at a CloseWatcher object when a close request was received and only fired if the cancel event that preceded the close one was not canceled.

The close event handler is where the code to close the UI component should be called: this ensures that the component will be closed properly either from the platform-specific close signal or from a call to CloseWatcher.requestClose().

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

addEventListener("close", (event) => { })

onclose = (event) => { }

Event type

An Event.

Examples

>

Using the close event

Use the close to listen for close requests.

watcher.addEventListener("close", () => {
  // Close your UI component
  sidebar.hide();
});

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Opera Safari Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet WebView Android WebView on iOS
close_event 126 126 preview 112 No 126 No 83 No 28.0 126 No

© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CloseWatcher/close_event