我为Firefox编写了以下用户脚本:
window.onload = function start() {
if (!Notification) {
alert("Your browser doesn't support notifications");
return;
}
foo();
}
function sendNotification(title, body, icon, linkToOpen) {
if (Notification.permission !== "granted") {
Notification.requestPermission();
}
var notification = new Notification(title, {
icon: icon,
body: body,
});
notification.onclick = function () {
window.open(linkToOpen);
}
}
function foo() {
try {
for (var i = 0; i < 1; ++i) { // here
sendNotification(
'Some title',
'Some body',
'http://cdn.akamai.steamstatic.com/steamcommunity/public/images/avatars/2f/2f6fd3197c8f38afc64d9309655362f23b46460a_full.jpg',
'https://www.google.ru/'
);
}
setTimeout(foo, 5000);
} catch (ex) {
alert(ex);
}
}
如果我在此代码中将1更改为2,则根本不会发出通知。
为什么呢?我究竟做错了什么?我该如何解决?