語法
js
let clearing = browser.notifications.clear(
id // string
)
引數
id-
string。要清除的通知的 ID。這與在notifications.create()的回撥中傳遞的 ID 相同。
返回值
一個 Promise,它將以布林值 fulfilled:如果通知已被清除,則為 true;如果未被清除(例如,因為 id 引用的通知不存在),則為 false。
示例
此示例顯示當用戶點選瀏覽器操作時一個通知,除非該通知已在顯示,在這種情況下它會清除該通知。
js
let myNotification = "my-notification";
function toggleAlarm(all) {
if (myNotification in all) {
browser.notifications.clear(myNotification);
} else {
browser.notifications.create(myNotification, {
type: "basic",
iconUrl: browser.runtime.getURL("icons/cake-48.png"),
title: "Am imposing title",
message: "Some interesting content",
});
}
}
function handleClick() {
let gettingAll = browser.notifications.getAll();
gettingAll.then(toggleAlarm);
}
browser.browserAction.onClicked.addListener(handleClick);
瀏覽器相容性
載入中…
注意: 此 API 基於 Chromium 的 chrome.notifications API。