【发布时间】:2017-03-31 18:42:12
【问题描述】:
我的 chrome 扩展程序使用通知。我打电话给他们:
function notifyMe(message) {
if (!Notification) {
alert('No desktop notifications possible!');
return;
}
if (Notification.permission !== "granted")
Notification.requestPermission();
else {
var notification = new Notification('Bot success!', {
icon: 'https://material-design.storage.googleapis.com/publish/material_v_9/0Bx4BSt6jniD7blViQzF0azNqZU0/style_icons_system_intro_principles_consistent.png',
body: message,
});
setTimeout(function() { notification.close() }, 5000);
notification.onclick = function () {
window.open("http://google.com");
};
}
}
notifyMe("I am a notification!");
当通知已经存在时,是否有办法更改消息、图标和标题?有没有办法从另一个函数关闭它,而不是函数本身内部的 5000 毫秒超时?
我通过定义 var notification 尝试了一些从外部关闭它的方法;在我的脚本开头允许从任何地方访问,但这并没有很好地工作。
这可能很明显,但我对 JS 还是有点陌生。对不起!
感谢任何帮助!
【问题讨论】:
标签: javascript google-chrome google-chrome-extension notifications