CloseWatcher Class

Listens to the close requests of the user (https://html.spec.whatwg.org/multipage/interaction.html#the-closewatcher-interface), e.g. the Escape key: a custom component (a picker, a sidebar) closes itself in the close event, as the dialogs and the popovers do with their own close watchers. A close request closes the close watchers of the most recent group of the window: the close watchers created without user activation are grouped with the previous one, so that a page cannot trap the close requests of the user.

public sealed class CloseWatcher : EventTarget
Inheritance
EventTarget CloseWatcher

Constructors

NameDescription
CloseWatcher(CloseWatcherOptions?)Creates a close watcher of the window of the current global object (https://html.spec.whatwg.org/multipage/interaction.html#dom-closewatcher).
CloseWatcher(Window, CloseWatcherOptions?)Creates a close watcher of a window (https://html.spec.whatwg.org/multipage/interaction.html#dom-closewatcher).

CloseWatcher overloads

CloseWatcher(CloseWatcherOptions?)

CloseWatcher.cs

Creates a close watcher of the window of the current global object (https://html.spec.whatwg.org/multipage/interaction.html#dom-closewatcher).

public CloseWatcher(CloseWatcherOptions? options = null)
Parameters
options CloseWatcherOptions?
The options, or null.
Exceptions
DomException
There is no current window, or its document is not fully active (InvalidStateError).
See also

CloseWatcher(Window, CloseWatcherOptions?)

CloseWatcher.cs

Creates a close watcher of a window (https://html.spec.whatwg.org/multipage/interaction.html#dom-closewatcher).

public CloseWatcher(Window window, CloseWatcherOptions? options = null)
Parameters
window Window
The window whose close requests are watched.
options CloseWatcherOptions?
The options, or null.
Exceptions
DomException
The document of the window is not fully active (InvalidStateError).

Properties

NameDescription
OnCancelGets or sets the event handler of the cancel event.
OnCloseGets or sets the event handler of the close event.

Gets or sets the event handler of the cancel event.

public Action<Event>? OnCancel { get; set; }

Gets or sets the event handler of the close event.

public Action<Event>? OnClose { get; set; }

Methods

NameDescription
Close()Closes the watcher: fires close, without cancel, and destroys it (https://html.spec.whatwg.org/multipage/interaction.html#dom-closewatcher-close).
Destroy()Destroys the watcher: it no longer receives the close requests and fires no event (https://html.spec.whatwg.org/multipage/interaction.html#dom-closewatcher-destroy).
RequestClose()Acts as if the user sent a close request to this close watcher: fires cancel (it can always be canceled), then closes the watcher (https://html.spec.whatwg.org/multipage/interaction.html#dom-closewatcher-requestclose).

Closes the watcher: fires close, without cancel, and destroys it (https://html.spec.whatwg.org/multipage/interaction.html#dom-closewatcher-close).

public void Close()

Destroys the watcher: it no longer receives the close requests and fires no event (https://html.spec.whatwg.org/multipage/interaction.html#dom-closewatcher-destroy).

public void Destroy()

RequestClose()

CloseWatcher.cs

Acts as if the user sent a close request to this close watcher: fires cancel (it can always be canceled), then closes the watcher (https://html.spec.whatwg.org/multipage/interaction.html#dom-closewatcher-requestclose).

public void RequestClose()