P
P
Peter2020-08-26 03:26:49
JavaScript
Peter, 2020-08-26 03:26:49

How to unsubscribe from notifications?

Created a subscription on the site.

function notifyMe() {
  // Let's check if the browser supports notifications
  if (!("Notification" in window)) {
    alert("This browser does not support desktop notification");
  }

  // Let's check whether notification permissions have already been granted
  else if (Notification.permission === "granted") {
    // If it's okay let's create a notification
    var notification = new Notification("Hi there!");
  }

  // Otherwise, we need to ask the user for permission
  else if (Notification.permission !== "denied") {
    Notification.requestPermission().then(function (permission) {
      // If the user accepts, let's create a notification
      if (permission === "granted") {
        var notification = new Notification("Hi there!");
      }
    });
  }

  // At last, if the user has denied notifications, and you 
  // want to be respectful there is no need to bother them anymore.
}


Everything is fine, but if the task is to unsubscribe, is it possible to do this in JavaScript, or can only the user already in the browser be able to unsubscribe?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex, 2020-08-26
@Kozack

In your question, I don't see any subscription. All you do is ask the user for permission to show notifications. And permissions for sites can only be controlled by the user.

P
Petr, 2020-08-26
Petersky @MOtoroller1983

That is, the user himself will not be able to remove the permission through the site only in the browser?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question