Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. CloseWatcher
  4. requestClose()

CloseWatcher: requestClose() method

Limited availability

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

Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.

TherequestClose() method of theCloseWatcher interface fires acancel event and if that event is not canceled withEvent.preventDefault(), proceeds to fire aclose event, and then finally deactivates the close watcher as ifdestroy() was called.

Syntax

js
requestClose()

Parameters

None.

Return value

None (undefined).

Examples

Using therequestClose() method

In this example, you have your own UI component (a picker), and you want to support both the platform's default close method (e.g., theEsc key) and your custom close method (a close button).

Theonclick handler of your UI component can callrequestClose to request a close and to route your close request through the sameonclose handler the platform close method uses.

js
const watcher = new CloseWatcher();const picker = setUpAndShowPickerDOMElement();let chosenValue = null;watcher.onclose = () => {  chosenValue = picker.querySelector("input").value;  picker.remove();};picker.querySelector(".close-button").onclick = () => watcher.requestClose();

Specifications

Specification
HTML
# dom-closewatcher-requestclose

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp