Class Notification
- Namespace
- CSharpToJavaScript.APIs.JS
- Assembly
- CSharpToJavaScript.dll
The Notification interface of the {{domxref("Notifications API", "", "", "nocode")}} is used to configure and display desktop notifications to the user.
[Value("Notification")]
public class Notification : EventTarget
- Inheritance
-
Notification
- Inherited Members
Remarks
These notifications' appearance and specific functionality vary across platforms but generally they provide a way to asynchronously provide information to the user.
Constructors
Notification()
public Notification()
Notification(string, NotificationOptions)
The Notification() constructor creates a new
Notification object instance, which represents a user notification.
public Notification(string title, NotificationOptions options = null)
Parameters
titlestringoptionsNotificationOptions
Remarks
NOTE
Trying to create a notification inside the ServiceWorkerGlobalScope using the
Notification()constructor will throw aTypeError. Use ShowNotification(string, NotificationOptions) instead.
Properties
Actions
NOTE
Experimentalactions read-only property of the Notification interface provides the actions available for users to choose from for interacting with the notification.
[Value("actions")]
public NotificationAction[] Actions { get; }
Property Value
- NotificationAction[]
A read-only array of actions. Each element in the array is an object with the following members:
Remarks
The actions are set using the actions option of the second argument for the ShowNotification(string, NotificationOptions) method and NotificationNotification constructor.
NOTE
Browsers typically limit the maximum number of actions they will display for a particular notification. Check the static MaxActions property to determine the limit.
Badge
The badge read-only property of the Notification interface returns a string containing the URL of an image to represent the notification when there is not enough space to display the notification itself such as for example, the Android Notification Bar. On Android devices, the badge should accommodate devices up to 4x resolution, about 96 by 96 px, and the image will be automatically masked.
[Value("badge")]
public string Badge { get; }
Property Value
- string
A string containing a URL.
Remarks
Body
The body read-only property of the
Notification interface indicates the body string of the notification, as
specified in the body option of the
Notification(string, NotificationOptions) constructor.
[Value("body")]
public string Body { get; }
Property Value
- string
A string.
Remarks
Data
The data read-only property of the
Notification interface returns a structured clone of the notification's
data, as specified in the data option of the
Notification(string, NotificationOptions) constructor.
[Value("data")]
public dynamic Data { get; }
Property Value
- dynamic
A structured clone.
Remarks
The notification's data can be any arbitrary data that you want associated with the
notification.
Dir
The dir read-only property of the Notification interface indicates the text direction of the notification, as specified in the dir option of the Notification(string, NotificationOptions) constructor.
[Value("dir")]
public NotificationDirection Dir { get; }
Property Value
- NotificationDirection
A string specifying the text direction. Possible values are:
NOTE
Most browsers seem to ignore explicit ltr and rtl settings, and just go with the browser-wide setting.
Remarks
Icon
The icon read-only property of the
Notification interface contains the URL of an icon to be displayed as
part of the notification, as specified in the icon option of the
Notification(string, NotificationOptions) constructor.
[Value("icon")]
public string Icon { get; }
Property Value
- string
A string.
Remarks
Image
NOTE
Experimentalimage read-only property of theNotification interface contains the URL of an image to be displayed as
part of the notification, as specified in the
image option of theNotification(string, NotificationOptions) constructor.
[Value("image")]
public string Image { get; }
Property Value
- string
A string.
Remarks
Lang
The lang read-only property of the
Notification interface indicates the language used in the notification,
as specified in the lang option of the
Notification(string, NotificationOptions) constructor.
[Value("lang")]
public string Lang { get; }
Property Value
- string
A string specifying the language tag.
Remarks
The language itself is specified using a string representing a language tag according to {{RFC(5646, "Tags for Identifying Languages (also known as BCP 47)")}}.
See the Sitepoint ISO 2 letter language codes page for a simple reference.
MaxActions
NOTE
ExperimentalmaxActions read-only static property of theNotification interface returns the maximum number of actions supported by
the device and the User Agent. Effectively, this is the maximum number of elements in
Actions array which will be respected by the User Agent.
[Value("maxActions")]
public static ulong MaxActions { get; }
Property Value
- ulong
An integer number which indicates the largest number of notification
actions that can be presented to the user by the User Agent and the device.
Remarks
Onclick
[Value("onclick")]
public EventHandlerNonNull Onclick { get; set; }
Property Value
Onclose
[Value("onclose")]
public EventHandlerNonNull Onclose { get; set; }
Property Value
Onerror
[Value("onerror")]
public EventHandlerNonNull Onerror { get; set; }
Property Value
Onshow
[Value("onshow")]
public EventHandlerNonNull Onshow { get; set; }
Property Value
Permission
The permission read-only static property of the Notification
interface indicates the current permission granted by the user for the current origin to
display web notifications.
[Value("permission")]
public static NotificationPermission Permission { get; }
Property Value
- NotificationPermission
A string representing the current permission. The value can be:
Remarks
Renotify
NOTE
Experimentalrenotify read-only property of theNotification interface specifies whether the user should be notified
after a new notification replaces an old one, as specified in the
renotifyoption of the Notification(string, NotificationOptions) constructor.
[Value("renotify")]
public bool Renotify { get; }
Property Value
- bool
A boolean value.
falseis the default;truemakes
the notification renotify the user.
Remarks
RequireInteraction
The requireInteraction read-only property of the Notification interface returns a boolean value indicating that a notification should remain active until the user clicks or dismisses it, rather than closing automatically.
[Value("requireInteraction")]
public bool RequireInteraction { get; }
Property Value
- bool
A boolean value.
Remarks
NOTE
This can be set when the notification is first created by setting the
requireInteractionoption totruein the options object of the Notification(string, NotificationOptions) constructor.
Silent
The silent read-only property of the
Notification interface specifies whether the notification should be
silent, i.e., no sounds or vibrations should be issued regardless of the device
settings. This is controlled via the silent option of the
Notification(string, NotificationOptions) constructor.
[Value("silent")]
public bool? Silent { get; }
Property Value
- bool?
A boolean value or
null. If set totrue, the notification is silent; if set tonull(the default value), the device's default settings are respected.
Remarks
Tag
The tag read-only property of the
Notification interface signifies an identifying tag for the notification,
as specified in the tag option of the
Notification(string, NotificationOptions) constructor.
[Value("tag")]
public string Tag { get; }
Property Value
- string
A string.
Remarks
The idea of notification tags is that more than one notification can share the same
tag, linking them together. One notification can then be programmatically replaced with
another to avoid the users' screen being filled up with a huge number of similar
notifications.
Timestamp
NOTE
Experimentaltimestamp read-only property of theNotification interface returns a number, as
specified in the
timestamp option of theNotification(string, NotificationOptions) constructor.
[Value("timestamp")]
public ulong Timestamp { get; }
Property Value
Remarks
The notification's timestamp can represent the time, in milliseconds since 00:00:00 UTC
on 1 January 1970, of the event for which the notification was created, or it can be an
arbitrary timestamp that you want associated with the notification. For example, a
timestamp for an upcoming meeting could be set in the future, whereas a timestamp for a
missed message could be set in the past.
Title
The title read-only property of the
Notification interface indicates the title of the notification, as
specified in the title parameter of the
Notification(string, NotificationOptions) constructor.
[Value("title")]
public string Title { get; }
Property Value
- string
A string.
Remarks
Vibrate
NOTE
Experimentalvibrate read-only property of the Notificationinterface specifies a vibration pattern
for the device's vibration hardware to emit when the notification fires. This is
specified in the
vibrate option of theNotification(string, NotificationOptions) constructor.
[Value("vibrate")]
public ulong[] Vibrate { get; }
Property Value
- ulong[]
A vibration pattern, as specified in the Vibration API spec.
Remarks
Methods
Close()
The close() method of the Notification interface is used to
close/remove a previously displayed notification.
[Value("close")]
public GlobalObject.Undefined Close()
Returns
Remarks
NOTE
This API shouldn't be used just to have the notification
removed from the screen after a fixed delay since this method will also remove the
notification from any notification tray, preventing users from interacting with it
after it was initially shown. A valid use for this API would be to remove a
notification that is no longer relevant (e.g., the user already read the notification
on the webpage in the case of a messaging app or the following song is already playing
in a music app).
RequestPermission(NotificationPermissionCallback)
The requestPermission() static method of the Notification interface requests permission from the user for the current origin to display notifications.
[Value("requestPermission")]
public static Task<NotificationPermission> RequestPermission(NotificationPermissionCallback deprecatedCallback = null)
Parameters
deprecatedCallbackNotificationPermissionCallback
Returns
- Task<NotificationPermission>
A Promise that resolves to a string with the permission picked by the user.
Possible values for this string are:The deprecated version of the method returnsundefined.
Remarks
The method returns a Promise that fulfills with a string indicating whether permission was granted or denied.