我正在创建一个具有丰富通知的google-chrome扩展。我需要在此通知中更改超时关闭,我需要一些帮助。这是我的代码。我已经尝试过window.close(),但它似乎在Chrome中不起作用。
var options = {
type: "basic",
title: "test",
message: "body here",
iconUrl: "icon.png"
};
var msj = chrome.notifications.create(options);
setTimeout(function () {
chrome.notifications.clear(msj); // how to close?
}, 1500);
Chrome api大多是异步的(一定要看看那个链接)。
chrome.notifications.create
不会立即创建通知,也不会返回ID。你需要为此使用回调:
chrome.notifications.create(options, function(msj) {
setTimeout(function() {
chrome.notifications.clear(msj);
}, 1500);
});