blob: 211947a1b8af02166d743e47250ff1018cef0d77 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
---
title: Notification.onclick
slug: Web/API/notification/onclick
tags:
- API
- DOM
- Notifications
- Propiedad
- Referencia
- onclick
translation_of: Web/API/Notification/onclick
---
<p>{{APIRef("Web Notifications")}}</p>
<p>La propiedad <code>onclick</code> 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.</p>
<h2 id="Syntax" name="Syntax">Sintaxis</h2>
<pre class="eval">Notification.onclick = function(event) { ... };
</pre>
<p>El comportamiento por defecto es mover el foco al viewport del <a href="https://html.spec.whatwg.org/multipage/browsers.html#browsing-context">sitio de contexto</a> de dicha notificación. Si no deseas este comportamiento, puedes llamar <code><a href="/en-US/docs/Web/API/Event/preventDefault">preventDefault()</a></code> en el objeto del evento.</p>
<h2 id="Ejemplos">Ejemplos</h2>
<p>En el siguiente ejemplo, utilizamos un manejador <code>onclick</code> para abrir un sitio web en una nueva pestaña (especificado con la inclusión del parámetro <code>'_blank'</code>) una vez que la notifación es cliqueada.</p>
<pre class="brush: js">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');
}</pre>
<h2 id="Especificaciones">Especificaciones</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('Web Notifications','#dom-notification-onclick','onclick')}}</td>
<td>{{Spec2('Web Notifications')}}</td>
<td>Living standard.</td>
</tr>
</tbody>
</table>
<h2 id="Compatibilidad_de_navegadores">Compatibilidad de navegadores</h2>
<p>{{Page("/en-US/docs/Web/API/Notification","Browser compatibility")}}</p>
<h2 id="Mira_también">Mira también</h2>
<ul>
<li>{{domxref("Notification")}}</li>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API">Usando la API de Notifications</a></li>
</ul>
|