Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

notifications.clear()

この記事はまだボランティアによって 日本語 に翻訳されていません。ぜひ MDN に参加して翻訳を手伝ってください!

Clears a notification, given its ID.

Syntax

chrome.notifications.clear(
  id,                            // string
  function(wasCleared) {...}     // optional function
)

This API is also available as browser.notifications.clear() in a version that returns a promise.

Parameters

id
string. The ID of the notification to clear. This is the same as the ID passed into notifications.create()'s callback.
callbackOptional
function. The function is passed the following arguments:
wasCleared
boolean. true if the notification was cleared, or false if it was not (for example, because the notification referenced by id did not exist).

Browser compatibility

Chrome Edge Firefox Firefox for Android Opera
Basic support Yes No 45.0 48.0 33

Examples

This example shows a notification when the user clicks a browser action, unless the notification was already being shown, in which case it clears the notification:

var myNotification = "my-notification";

chrome.browserAction.onClicked.addListener(function () {
  chrome.notifications.getAll((all) => {
    if (myNotification in all) {
      chrome.notifications.clear(myNotification);
    } else {
      chrome.notifications.create(myNotification, {
        "type": "basic",
        "iconUrl": chrome.extension.getURL("icons/cake-48.png"),
        "title": "Am imposing title",
        "message": "Some interesting content"
      });
    }
  });
});

Acknowledgements

This API is based on Chromium's chrome.notifications API.

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.

ドキュメントのタグと貢献者

 このページの貢献者: Makyen, wbamberg
 最終更新者: Makyen,