Chrome extension development: auto close the notification box

前端 未结 5 873
眼角桃花
眼角桃花 2021-01-02 16:35

After doing something I run this code:

var notification = webkitNotifications.createNotification(
   \'icon.png\',  // icon url - can be relative
  \'Done!\'         


        
5条回答
  •  無奈伤痛
    2021-01-02 17:08

    function show(title, message, icon) {
    try {
        icon = icon || 'src/img/icons/icon48.png';
        var self = this;
        var isClosed = false;
        var notificationId = "posting_" + Math.random();
    
        chrome.notifications.create(notificationId, {
            type: "basic",
            title: title + "!",
            message: message,
            iconUrl: icon
        }, function (nId) {
        });
    
        setTimeout(function () {
            if (!isClosed)
                chrome.notifications.clear(notificationId, function (wasCleared) {
                });
        }, 3000);
    } catch (e) {
        alert(e.message);
    }
    

    }

    ok, when i created notification remeber the id notificationId and settimeout clear this id

提交回复
热议问题