Notification Class
A notification shown to the user (https://notifications.spec.whatwg.org/#notification), by BrowsingContextOptions.ShowNotification once the notifications permission is granted. The host calls Notification.Click when the user activates the notification and Notification.Dismiss when the user closes it.
public sealed class Notification : EventTargetRemarks
The error event is fired when the permission is not granted. A notification whose tag is not empty replaces the notification of the same origin with the same tag (its close event is fired). The persistent notifications of the service workers (showNotification()) and the actions are not supported.
See also
- Inheritance
EventTargetNotification
Constructors
| Name | Description |
|---|---|
| Notification(string, NotificationOptions?) | Creates a notification and shows it (https://notifications.spec.whatwg.org/#dom-notification-notification): the show event is fired once it is shown, or the error event when the permission is not granted. |
Notification(string, NotificationOptions?)
Notification.csCreates a notification and shows it (https://notifications.spec.whatwg.org/#dom-notification-notification): the show event is fired once it is shown, or the error event when the permission is not granted.
public Notification(string title, NotificationOptions? options = null)Parameters
titlestring- The title of the notification.
optionsNotificationOptions?- The options of the notification.
Exceptions
TypeErrorException- The constructor is called in a service worker, the options have actions, or
renotifyis set without tag.
See also
Properties
| Name | Description |
|---|---|
| Actions | Gets the actions of the notification (https://notifications.spec.whatwg.org/#dom-notification-actions): always empty. |
| Badge | Gets the absolute URL of the badge, or the empty string. |
| Body | Gets the body of the notification. |
| Data | Gets a deserialization of the data of the notification (the same value each time). |
| Dir | Gets the direction of the text. |
| Icon | Gets the absolute URL of the icon, or the empty string. |
| Image | Gets the absolute URL of the image, or the empty string. |
| IsShown | Gets whether the notification is shown: it is in the list of notifications of the browsing contexts. |
| Lang | Gets the language of the text. |
| MaxActions | Gets the maximum number of actions of a notification (https://notifications.spec.whatwg.org/#dom-notification-maxactions): 0, the actions are not supported. |
| Navigate | Gets the absolute URL to navigate to when the notification is activated, or the empty string. |
| OnClick | Gets or sets the event handler of the click event. |
| OnClose | Gets or sets the event handler of the close event. |
| OnError | Gets or sets the event handler of the error event. |
| OnShow | Gets or sets the event handler of the show event. |
| Permission | Gets whether the user allows the origin of the current global object to show notifications (https://notifications.spec.whatwg.org/#dom-notification-permission), read from the permission store (BrowsingContextOptions.Permissions). |
| Renotify | Gets whether the user is alerted again when the notification replaces another one. |
| RequireInteraction | Gets whether the notification stays until the user activates or closes it. |
| Silent | Gets whether the notification is silent, or null for the default of the device. |
| Tag | Gets the tag of the notification. |
| Timestamp | Gets the time of the notification, in milliseconds since the Unix epoch. |
| Title | Gets the title of the notification. |
Actions
Notification.csGets the actions of the notification (https://notifications.spec.whatwg.org/#dom-notification-actions): always empty.
public IReadOnlyList<NotificationAction> Actions { get; }Badge
Notification.csGets the absolute URL of the badge, or the empty string.
public string Badge { get; }Body
Notification.csGets the body of the notification.
public string Body { get; }Data
Notification.csGets a deserialization of the data of the notification (the same value each time).
public object? Data { get; }Icon
Notification.csGets the absolute URL of the icon, or the empty string.
public string Icon { get; }Image
Notification.csGets the absolute URL of the image, or the empty string.
public string Image { get; }IsShown
Notification.csLang
Notification.csGets the language of the text.
public string Lang { get; }MaxActions
Notification.csGets the maximum number of actions of a notification (https://notifications.spec.whatwg.org/#dom-notification-maxactions): 0, the actions are not supported.
public static uint MaxActions { get; }OnClick
Notification.csGets or sets the event handler of the click event.
OnClose
Notification.csGets or sets the event handler of the close event.
OnError
Notification.csGets or sets the event handler of the error event.
OnShow
Notification.csGets or sets the event handler of the show event.
Permission
Notification.csGets whether the user allows the origin of the current global object to show notifications (https://notifications.spec.whatwg.org/#dom-notification-permission), read from the permission store (BrowsingContextOptions.Permissions).
public static NotificationPermission Permission { get; }Property value
See also
Renotify
Notification.csGets whether the user is alerted again when the notification replaces another one.
public bool Renotify { get; }RequireInteraction
Notification.csGets whether the notification stays until the user activates or closes it.
public bool RequireInteraction { get; }Property value
See also
Silent
Notification.csGets whether the notification is silent, or null for the default of the device.
public bool? Silent { get; }Gets the tag of the notification.
public string Tag { get; }Timestamp
Notification.csGets the time of the notification, in milliseconds since the Unix epoch.
public ulong Timestamp { get; }Title
Notification.csGets the title of the notification.
public string Title { get; }Methods
| Name | Description |
|---|---|
| Click() | Activates the notification, as when the user clicks it (https://notifications.spec.whatwg.org/#activating-a-notification): fires its click event, and focuses its window unless the event is canceled. It must be called on the thread of the event loop of the browsing context. |
| Close() | Closes the notification (https://notifications.spec.whatwg.org/#dom-notification-close), and fires its close event. |
| Dismiss() | Closes the notification, as when the user dismisses it (https://notifications.spec.whatwg.org/#closing-a-notification): fires its close event. BrowsingContextOptions.CloseNotification is not called. It must be called on the thread of the event loop of the browsing context. |
| RequestPermission(NotificationPermissionCallback?) | Asks the user to allow the origin to show notifications (https://notifications.spec.whatwg.org/#dom-notification-requestpermission), with BrowsingContextOptions.RequestPermission, unless the permission is already granted or denied. |
Click()
Notification.csActivates the notification, as when the user clicks it (https://notifications.spec.whatwg.org/#activating-a-notification): fires its click event, and focuses its window unless the event is canceled. It must be called on the thread of the event loop of the browsing context.
public void Click()Close()
Notification.csCloses the notification (https://notifications.spec.whatwg.org/#dom-notification-close), and fires its close event.
public void Close()Dismiss()
Notification.csCloses the notification, as when the user dismisses it (https://notifications.spec.whatwg.org/#closing-a-notification): fires its close event. BrowsingContextOptions.CloseNotification is not called. It must be called on the thread of the event loop of the browsing context.
public void Dismiss()RequestPermission(NotificationPermissionCallback?)
Notification.csAsks the user to allow the origin to show notifications (https://notifications.spec.whatwg.org/#dom-notification-requestpermission), with BrowsingContextOptions.RequestPermission, unless the permission is already granted or denied.
public static Task<NotificationPermission> RequestPermission(NotificationPermissionCallback? deprecatedCallback = null)Parameters
deprecatedCallbackNotificationPermissionCallback?- A callback invoked with the permission, before the task completes.