Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The CloseWatcher
interface listens and responds to close requests.
Some UI components have "close behavior", meaning that the component appears, and the user can close it when they are finished with it. For example: sidebars, popups, dialogs, or notifications.
Users generally expect to be able to use a particular mechanism to close these elements, and the mechanism tends to be device-specific. For example, on a device with a keyboard it might be the Esc key, but Android might use the back button. For built-in components, such as popover or <dialog>
elements, the browser takes care of these differences, closing the element when the user performs the close action appropriate for the device. However, when a web developer implements their own closable UI component (for example, a sidebar), it is hard to implement this kind of device-specific close behavior. The CloseWatcher
interface solves this problem by delivering a close
event to the when the user executes the close action for the device.
The CloseWatcher
interface inherits from EventTarget
.