这篇翻译不完整。请帮忙从英语翻译这篇文章

Notification 接口的 onclick属性指定一个事件侦听器来接收 click 事件。

当用户点击一个显示的Notification时,会发生这些事件。

Syntax

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

该方法的默认行为是将焦点移到与该通知相关联的 browsing context 的窗口. 如果你不希望这样, 可以在 event 对象上调用 preventDefault().

Examples

在下面这个例子中,我们使用 onclick 处理程序来监听点击通知的事件, 并在新窗口(通过包含一个参数'_blank')打开一个页面:

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
onclick
Living Standard 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.

See also

文档标签和贡献者

标签: 
此页面的贡献者: linfeng2gh, xgqfrms-GitHub
最后编辑者: linfeng2gh,