Notification: data 属性

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

安全上下文: 此功能仅在安全上下文(HTTPS)中可用,且支持此功能的浏览器数量有限。

注意:此功能在 Web Workers 中可用。

dataNotification 接口的一个只读属性,它返回一个对通知数据的结构化克隆,该数据是在 Notification() 构造函数的 data 选项中指定的。

通知的数据可以是您希望与通知关联的任何任意数据。

一个结构化克隆。

示例

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

js
const options = {
  body: "Your code submission has received 3 new review comments.",
  data: {
    url: "https://example.com/review/12345",
    status: "open",
  },
};

const n = new Notification("New review activity", options);

console.log(n.data); // Logs the data object

规范

规范
Notifications API
# dom-notification-data

浏览器兼容性

另见