0

我正在显示通知,问题是每次加载页面时它们都会显示,因此将标签保存到本地存储,然后如果标签在本地存储中,则不显示通知,但它会保存到本地存储,但不会t 停止显示通知。代码如下:

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();

};

谢谢你的帮助。

4

0 回答 0