我正在使用Notification API,但我无法使它与SetInterval()一起工作,有人可以指出我做错了什么。只要我点击该事件,通知只会显示一次。这里是我的代码:使用setInterval和JavaScript
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('notifyBtn').addEventListener('click', function() {
if (!('Notification' in window)) {
alert('Web Notification is not supported');
return;
} else {
setInterval(Notification.requestPermission(function(permission) {
var notification = new Notification("Hi there!", {
body: 'I am here to talk about HTML5 Web Notification API',
icon: 'icon.png',
dir: 'auto'
});
setTimeout(function() {
notification.close();
}, 2000);
}),5000);
}
;
});
});
我真的被卡住了,请halp。
你检查控制台抛出一些错误? –
我相信你的setInterval函数是错误的 –