Notification.onclick
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
BCD tables only load in the browser