Traducción en curso

The Notification() constructor creates a new Notification object instance, which represents a user notification.

Nota: Esta característica está disponible en Web Workers.

Syntax

var myNotification = new Notification(title, options);

Parameters

title
Defines a title for the notification, which will be shown at the top of the notification window when it is fired.
options Optional
An options object containing any custom settings that you want to apply to the notification. The possible options are:
  • dir: The direction in which to display the notification. It defaults to auto, which just adopts the browser's language setting behavior, but you can override that behaviour by setting values of ltr and rtl (although most browsers seem to ignore these settings.)
  • lang: The notification's language, as specified using a DOMString representing a BCP 47 language tag. See the Sitepoint ISO 2 letter language codes page for a simple reference.
  • badge: A USVString containing the URL of the image used to represent the notification when there is not enough space to display the notification itself.
  • body: A DOMString representing the body text of the notification, which will be displayed below the title.
  • tag: A DOMString representing an identifying tag for the notification.
  • icon: A USVString containing the URL of an icon to be displayed in the notification.
  • image: a USVString containing the URL of an image to be displayed in the notification.
  • data: Arbitrary data that you want associated with the notification. This can be of any data type.
  • vibrate: A vibration pattern for the device's vibration hardware to emit when the notification fires.
  • renotify: A Boolean specifying whether the user should be notified after a new notification replaces an old one. The default is false, which means they won't be notified.
  • requireInteraction: Indicates that a notification should remain active until the user clicks or dismisses it, rather than closing automatically. The default value is false.
  • actions: An array of NotificationActions representing the actions available to the user when the notification is presented. These are options the user can choose among in order to act on the action within the context of the notification itself. The action's name is sent to the service worker notification handler to let it know the action was selected by the user.

The following options are listed in the most up-to-date spec, but are not supported in any browsers yet. It is advisable to keep checking back regularly to see if the status of these has updated, and let us know if you find any out of date information.

  • silent: A Boolean specifying whether the notification should be silent, i.e. no sounds or vibrations should be issued, regardless of the device settings. The default is false, which means it won't be silent.
  • noscreen: A Boolean specifying whether the notification firing should enable the device's screen or not. The default is false, which means it will enable the screen.
  • sticky: A Boolean specifying whether the notification should be 'sticky', i.e. not easily clearable by the user. The default is false, which means it won't be sticky.

Example

In our Emogotchi demo (see source code), we run a simple spawnNotification() function when we want to fire a notification — this is passed arguments to specify the body, icon and title we want, then it creates the necessary options object and fires the notification using the Notification() constructor.

function spawnNotification(theBody,theIcon,theTitle) {
  var options = {
      body: theBody,
      icon: theIcon
  }
  var n = new Notification(theTitle,options);
}

Specifications

Specification Status Comment
Notifications API
La definición de 'Notification()' en esta especificación.
Living Standard Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Soporte básicoChrome Soporte completo 22
Soporte completo 22
Soporte completo 5
Prefijado
Prefijado Requiere de un prefijo de vendedor : webkit
Edge Soporte completo SiFirefox Soporte completo 22
Soporte completo 22
Soporte completo 4
Prefijado
Prefijado Requiere de un prefijo de vendedor : moz
IE Sin soporte NoOpera Soporte completo 25Safari Soporte completo 6WebView Android Sin soporte NoChrome Android Soporte completo SiEdge Mobile ? Firefox Android Soporte completo 22
Soporte completo 22
Soporte completo 4
Prefijado
Prefijado Requiere de un prefijo de vendedor : moz
Opera Android Soporte completo SiSafari iOS Sin soporte NoSamsung Internet Android ?

Leyenda

Soporte completo  
Soporte completo
Sin soporte  
Sin soporte
Compatibility unknown  
Compatibility unknown
Requiere de un prefijo de proveedor o un de nombre diferente para su uso.
Requiere de un prefijo de proveedor o un de nombre diferente para su uso.

Chrome notes

Starting in Chrome 49, notifications do not work in incognito mode.

Internet Explorer notes

Since Version 38.14352 of MS Edge Notification API is suported. Wikipedia - MS Edge

IE 11 and < is not supported.

Safari notes

See also

Etiquetas y colaboradores del documento

Colaboradores en esta página: mdnwebdocs-bot, BubuAnabelas, alery123456
Última actualización por: mdnwebdocs-bot,