Notification:data 属性

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

安全上下文: 此项功能仅在一些支持的浏览器安全上下文(HTTPS)中可用。

备注: 此特性在 Web Worker 中可用。

Notification 接口的 data 只读属性根据 Notification() 构造函数的 data 选项返回一个通知数据的结构化克隆。

通知的数据可以是任何你想要与通知关联的任意数据。

一个结构化克隆的数据。

示例

以下代码段会触发一条通知。一个简单的 options 对象被创建,然后使用 Notification() 构造函数触发通知。

js
const options = {
  body: "你提交的代码收到了 3 条新的审阅意见。",
  data: {
    url: "https://example.com/review/12345",
    status: "open",
  },
};

const n = new Notification("新评论活动", options);

console.log(n.data); // 打印 data 对象

规范

Specification
Notifications API
# dom-notification-data

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
data

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.

参见