--- title: Notification.onclick slug: Web/API/notification/onclick tags: - API - DOM - Notifications - Propiedad - Referencia - onclick translation_of: Web/API/Notification/onclick ---

{{APIRef("Web Notifications")}}

La propiedad onclick de la interfaz {{domxref("Notification")}} especifica un event listener para recibir eventos {{event("click")}}. Estos eventos ocurren cuando el usuario hace un click sobre el {{domxref("Notification")}} mostrado.

Sintaxis

Notification.onclick = function(event) { ... };

El comportamiento por defecto es mover el foco al viewport del sitio de contexto de dicha notificación. Si no deseas este comportamiento, puedes llamar preventDefault() en el objeto del evento.

Ejemplos

En el siguiente ejemplo, utilizamos un manejador onclick para abrir un sitio web en una nueva pestaña (especificado con la inclusión del parámetro '_blank') una vez que la notifación es cliqueada.

notification.onclick = function(event) {
  event.preventDefault(); // Previene al buscador de mover el foco a la pestaña del Notification
  window.open('http://www.mozilla.org', '_blank');
}

Especificaciones

Specification Status Comment
{{SpecName('Web Notifications','#dom-notification-onclick','onclick')}} {{Spec2('Web Notifications')}} Living standard.

Compatibilidad de navegadores

{{Page("/en-US/docs/Web/API/Notification","Browser compatibility")}}

Mira también