我正在显示通知,每次加载页面时都会显示问题,因此将标记保存到本地存储,然后如果标记位于本地存储中则不显示通知,但是它会保存到本地存储,但不会停止显示通知。代码如下:
Notification.requestPermission().then(function(result) {
if (result === 'denied') {
console.log('Permission wasn\'t granted. Allow a retry.');
return;
}
if (result === 'default') {
console.log('The permission request was dismissed.');
return;
}
var note = new Notification("New title", {body:"example here", icon:"the icon", tag:"431",
})
window.localStorage.setItem('Notification' , note.tag);
job_posted.onclick = function(){
location.href = 'https://www.example.com/page.php?id=343';
}
});
if(localStorage.getItem("Notification")){
Notification.close();
};
感谢您的帮助。