【发布时间】:2017-11-27 18:49:26
【问题描述】:
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"});
});
【问题讨论】:
标签: javascript jquery google-chrome-extension notifications