CloseWatcher: close event

فهرست فصل‌ها دانلود آرشیوناشر

MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونه‌کد

{{APIRef("HTML DOM")}}

A close event is fired at a {{domxref("CloseWatcher")}} object when a close request was received and only fired if the {{domxref("CloseWatcher.cancel_event", "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 {{domxref("CloseWatcher.requestClose()")}}.

Syntax

Use the event name in {{domxref("EventTarget/addEventListener", "addEventListener()")}}:

js-nolint
addEventListener("close", (event) => { })

Alternatively, assign to the event handler property of the interface:

js-nolint
onclose = (event) => { }

Event type

An {{domxref("Event")}}.

Examples

Using the close event

Use the close to listen for close requests.

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

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}