0

I'm showing notifications, issue is they show every time the page is loaded, so saving the tag to local storage, then if tag is in local storage don't show the notification, however it saves to the local storage, but doesn't stop showing the notification. code is below:

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

};

Thanks for any help.

bob
  • 466
  • 1
  • 7
  • 27
  • i think your problem is solved fast.both, local and session storage cant store objects. only strings are working. make JSON.stringify to your object on write and JSON.parse on reading – mtizziani Feb 19 '17 at 15:51
  • It's reading at a string in local storage. if it's an object it would be key -> [object] value -> [object] however, i can see key -> Notification value -> 431 – bob Feb 19 '17 at 18:06

0 Answers0