Esta tradução está incompleta. Por favor, ajude a traduzir este artigo.

A propriedade onclick  de  Notification interface specifies an event listener to receive click events. These events occur when the user clicks on a displayed Notification.

Syntax

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

The default behavior is to move the focus to the viewport of the notification's related browsing context. If you don't want that behaviour, call preventDefault() on the event object.

Examples

In the following example, we use an onclick handler to open a webpage in a new tab (specified by the inclusion of the '_blank' parameter) once a notification is clicked:

notification.onclick = function(event) {
  event.preventDefault(); // prevent the browser from focusing the Notification's tab
  window.open('http://www.mozilla.org', '_blank');
}

Specifications

Specification Status Comment
Notifications API
The definition of 'onclick' in that specification.
Padrão em tempo real Living standard.

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support

221

5 -webkit-

Yes

22

4 -moz-

No256
Available in workers45 Yes41 No32 ?
Secure contexts only62 ? ? No49 ?
Notification() constructor

22

5 webkit

Yes

22

4 moz

No256
actions53 No No No39 ?
badge53 No No No39 ?
body Yes ? Yes No ? ?
data Yes ? Yes No ? ?
dir Yes ? Yes No ? ?
icon

22

5 -webkit-

?

22

4 -moz-

No25 No
image53 ? No No40 ?
lang Yes ? Yes No ? ?
maxActions Yes ? No No ? ?
onclick Yes ? No No ? ?
onclose Yes ? Yes No ? ?
onerror Yes ? No No ? ?
onshow Yes ? Yes No ? ?
permission Yes ? Yes No ? ?
renotify50 No No No37 No
requireInteraction Yes17 No No ? ?
silent4317 No No30 No
tag Yes ? Yes No ? ?
timestamp Yes17 No No ? ?
title Yes ? No No ? ?
vibrate53 No No No39 ?
close Yes ? Yes No ? ?
requestPermission46 ?47 No40 ?
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support No Yes ?

22

4 -webkit-

Yes No ?
Available in workers No45 Yes4132 No ?
Secure contexts only No62 ? ?49 No ?
Notification() constructor No Yes ?

22

4 moz

Yes No ?
actions No53 No No39 No ?
badge No53 No No39 No ?
body No Yes ? Yes ? No ?
data No Yes ? Yes ? No ?
dir No Yes ? Yes ? No ?
icon No Yes ?

22

4 -moz-

Yes No ?
image No53 ? No40 No ?
lang No Yes ? Yes ? No ?
maxActions No Yes ? No ? No ?
onclick No Yes ? No ? No ?
onclose No Yes ? Yes ? No ?
onerror No Yes ? No ? No ?
onshow No Yes ? Yes ? No ?
permission No Yes ? Yes ? No ?
renotify No50 No No37 No ?
requireInteraction No Yes17 No ? No ?
silent No4317 No30 No ?
tag No Yes ? Yes ? No ?
timestamp No Yes17 No ? No ?
title No Yes ? No ? No ?
vibrate No53 No No39 No ?
close No Yes ? Yes ? No ?
requestPermission No46 ? Yes40 No ?

1. Before Chrome 22, the support for notification followed an old prefixed version of the specification and used the navigator.webkitNotifications object to instantiate a new notification. Before Chrome 32, Notification.permission was not supported. Before Chrome 42, service worker additions were not supported. Starting in Chrome 49, notifications do not work in incognito mode.

Veja Também

Etiquetas do documento e colaboradores

Colaboradores desta página: dansenpai
Última atualização por: dansenpai,