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

瀏覽器相容性

另見