Notification.onclick - Web API 接口参考 编辑
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
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. Update compatibility data on GitHubDesktop | Mobile | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | Safari on iOS | Samsung Internet | |
Basic support | Chrome Full support 22Notes
| Edge Full support Yes | Firefox Full support 22
| IE No support No | Opera Full support 25 | Safari Full support 6 | WebView Android No support No | Chrome Android Full support Yes | Edge Mobile ? | Firefox Android Full support 22
| Opera Android Full support Yes | Safari iOS No support No | Samsung Internet Android ? |
Available in workers | Chrome Full support 45 | Edge Full support Yes | Firefox Full support 41 | IE No support No | Opera Full support 32 | Safari ? | WebView Android No support No | Chrome Android Full support 45 | Edge Mobile Full support Yes | Firefox Android Full support 41 | Opera Android Full support 32 | Safari iOS No support No | Samsung Internet Android ? |
Secure contexts only | Chrome Full support 62 | Edge ? | Firefox ? | IE No support No | Opera Full support 49 | Safari ? | WebView Android No support No | Chrome Android Full support 62 | Edge Mobile ? | Firefox Android ? | Opera Android Full support 49 | Safari iOS No support No | Samsung Internet Android ? |
Notification() constructor | Chrome Full support 22
| Edge Full support Yes | Firefox Full support 22
| IE No support No | Opera Full support 25 | Safari Full support 6 | WebView Android No support No | Chrome Android Full support Yes | Edge Mobile ? | Firefox Android Full support 22
| Opera Android Full support Yes | Safari iOS No support No | Samsung Internet Android ? |
actions | Chrome Full support 53 | Edge Full support 18 | Firefox No support No | IE No support No | Opera Full support 39 | Safari ? | WebView Android No support No | Chrome Android Full support 53 | Edge Mobile No support No | Firefox Android No support No | Opera Android Full support 39 | Safari iOS No support No | Samsung Internet Android ? |
badge | Chrome Full support 53 | Edge Full support 18 | Firefox No support No | IE No support No | Opera Full support 39 | Safari ? | WebView Android No support No | Chrome Android Full support 53 | Edge Mobile No support No | Firefox Android No support No | Opera Android Full support 39 | Safari iOS No support No | Samsung Internet Android ? |
body | Chrome Full support Yes | Edge ? | Firefox Full support Yes | IE No support No | Opera ? | Safari ? | WebView Android No support No | Chrome Android Full support Yes | Edge Mobile ? | Firefox Android Full support Yes | Opera Android ? | Safari iOS No support No | Samsung Internet Android ? |
data | Chrome Full support Yes | Edge ? | Firefox Full support Yes | IE No support No | Opera ? | Safari ? | WebView Android No support No | Chrome Android Full support Yes | Edge Mobile ? | Firefox Android Full support Yes | Opera Android ? | Safari iOS No support No | Samsung Internet Android ? |
dir | Chrome Full support Yes | Edge ? | Firefox Full support Yes | IE No support No | Opera ? | Safari ? | WebView Android No support No | Chrome Android Full support Yes | Edge Mobile ? | Firefox Android Full support Yes | Opera Android ? | Safari iOS No support No | Samsung Internet Android ? |
icon | Chrome Full support 22
| Edge ? | Firefox Full support 22
| IE No support No | Opera Full support 25 | Safari No support No | WebView Android No support No | Chrome Android Full support Yes | Edge Mobile ? | Firefox Android Full support 22
| Opera Android Full support Yes | Safari iOS No support No | Samsung Internet Android ? |
image | Chrome Full support 53 | Edge Full support 18 | Firefox No support No | IE No support No | Opera Full support 40 | Safari ? | WebView Android No support No | Chrome Android Full support 53 | Edge Mobile ? | Firefox Android No support No | Opera Android Full support 40 | Safari iOS No support No | Samsung Internet Android ? |
lang | Chrome Full support Yes | Edge ? | Firefox Full support Yes | IE No support No | Opera ? | Safari ? | WebView Android No support No | Chrome Android Full support Yes | Edge Mobile ? | Firefox Android Full support Yes | Opera Android ? | Safari iOS No support No | Samsung Internet Android ? |
maxActions | Chrome Full support Yes | Edge Full support 18 | Firefox No support No | IE No support No | Opera ? | Safari ? | WebView Android No support No | Chrome Android Full support Yes | Edge Mobile ? | Firefox Android No support No | Opera Android ? | Safari iOS No support No | Samsung Internet Android ? |
onclick | Chrome Full support Yes | Edge ? | Firefox No support No | IE No support No | Opera ? | Safari ? | WebView Android No support No | Chrome Android Full support Yes | Edge Mobile ? | Firefox Android No support No | Opera Android ? | Safari iOS No support No | Samsung Internet Android ? |
onclose | Chrome Full support Yes | Edge ? | Firefox Full support Yes | IE No support No | Opera ? | Safari ? | WebView Android No support No | Chrome Android Full support Yes | Edge Mobile ? | Firefox Android Full support Yes | Opera Android ? | Safari iOS No support No | Samsung Internet Android ? |
onerror | Chrome Full support Yes | Edge ? | Firefox No support No | IE No support No | Opera ? | Safari ? | WebView Android No support No | Chrome Android Full support Yes | Edge Mobile ? | Firefox Android No support No | Opera Android ? | Safari iOS No support No | Samsung Internet Android ? |
onshow | Chrome Full support Yes | Edge ? | Firefox Full support Yes | IE No support No | Opera ? | Safari ? | WebView Android No support No | Chrome Android Full support Yes | Edge Mobile ? | Firefox Android Full support Yes | Opera Android ? | Safari iOS No support No | Samsung Internet Android ? |
permission | Chrome Full support Yes | Edge ? | Firefox Full support Yes | IE No support No | Opera ? | Safari ? | WebView Android No support No | Chrome Android Full support Yes | Edge Mobile ? | Firefox Android Full support Yes | Opera Android ? | Safari iOS No support No | Samsung Internet Android ? |
renotify | Chrome Full support 50 | Edge No support No | Firefox No support No | IE No support No | Opera Full support 37 | Safari No support No | WebView Android No support No | Chrome Android Full support 50 | Edge Mobile No support No | Firefox Android No support No | Opera Android Full support 37 | Safari iOS No support No | Samsung Internet Android ? |
requireInteraction | Chrome Full support Yes | Edge Full support 17 | Firefox No support No | IE No support No | Opera ? | Safari ? | WebView Android No support No | Chrome Android Full support Yes | Edge Mobile No support No | Firefox Android No support No | Opera Android ? | Safari iOS No support No | Samsung Internet Android ? |
silent | Chrome Full support 43 | Edge Full support 17 | Firefox No support No | IE No support No | Opera Full support 30 | Safari No support No | WebView Android No support No | Chrome Android Full support 43 | Edge Mobile No support No | Firefox Android No support No | Opera Android Full support 30 | Safari iOS No support No | Samsung Internet Android ? |
tag | Chrome Full support Yes | Edge ? | Firefox Full support Yes | IE No support No | Opera ? | Safari ? | WebView Android No support No | Chrome Android Full support Yes | Edge Mobile ? | Firefox Android Full support Yes | Opera Android ? | Safari iOS No support No | Samsung Internet Android ? |
timestamp | Chrome Full support Yes | Edge Full support 17 | Firefox No support No | IE No support No | Opera ? | Safari ? | WebView Android No support No | Chrome Android Full support Yes | Edge Mobile No support No | Firefox Android No support No | Opera Android ? | Safari iOS No support No | Samsung Internet Android ? |
title | Chrome Full support Yes | Edge ? | Firefox No support No | IE No support No | Opera ? | Safari ? | WebView Android No support No | Chrome Android Full support Yes | Edge Mobile ? | Firefox Android No support No | Opera Android ? | Safari iOS No support No | Samsung Internet Android ? |
vibrate | Chrome Full support 53 | Edge No support No | Firefox No support No | IE No support No | Opera Full support 39 | Safari ? | WebView Android No support No | Chrome Android Full support 53 | Edge Mobile No support No | Firefox Android No support No | Opera Android Full support 39 | Safari iOS No support No | Samsung Internet Android ? |
close | Chrome Full support Yes | Edge ? | Firefox Full support Yes | IE No support No | Opera ? | Safari ? | WebView Android No support No | Chrome Android Full support Yes | Edge Mobile ? | Firefox Android Full support Yes | Opera Android ? | Safari iOS No support No | Samsung Internet Android ? |
requestPermission | Chrome Full support 46 | Edge ? | Firefox Full support 47 | IE No support No | Opera Full support 40 | Safari ? | WebView Android No support No | Chrome Android Full support 46 | Edge Mobile ? | Firefox Android Full support Yes | Opera Android Full support 40 | Safari iOS No support No | Samsung Internet Android ? |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
- See implementation notes.
- See implementation notes.
- Requires a vendor prefix or different name for use.
- Requires a vendor prefix or different name for use.
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论