将Web保存保存到本地存储后关闭Web通知的问题

时间:2017-02-19 15:32:11

标签: javascript local-storage web-notifications

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

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

};

感谢您的帮助。

0 个答案:

没有答案