Chrome扩展程序:点击通知会打开多个标签

时间:2017-11-27 18:49:27

标签: javascript jquery google-chrome-extension notifications

chrome.runtime.onMessage.addListener(function(msg, sender) {

    var options = {
        type: "basic",
        title: msg.title,
        message: "Price: " + msg.price + "\nFinished ",
        iconUrl: "icon.png"
    };

    chrome.notifications.create(options);

    chrome.notifications.onClicked.addListener(function() {
        chrome.tabs.create({url: "https://example.com/" + msg.link + "/a"});
    });

});

当我第一次点击通知时,它会打开一个新标签。当我第二次点击通知时,它会打开两个新标签,依此类推。如何才能使通知只打开一个标签?

我看过Chrome extension: Creating a new tab after clicking on the notification并尝试过建议(如下所示),但这会导致点击通知时没有发生任何事情。

chrome.runtime.onMessage.addListener(function(msg, sender) {

    var options = {
        type: "basic",
        title: msg.title,
        message: "Price: " + msg.price + "\nFinished ",
        iconUrl: "icon.png"
    };

    chrome.notifications.create(options);

});

chrome.notifications.onClicked.addListener(function() {
    chrome.tabs.create({url: "https://example.com/" + msg.link + "/a"});
});

1 个答案:

答案 0 :(得分:1)

您需要跟踪notificationId及其应该引导的链接。例如:

Unit: seconds
                                           expr        min          lq       mean      median         uq       max neval
 x[V1 == x[V1 %in% z, max(.SD), ], , which = T] 0.00076113 0.000871416 0.02571112 0.000945884 0.00109958 0.6195882    25