A
A
Alexey2019-07-30 15:31:42
JavaScript
Alexey, 2019-07-30 15:31:42

Notifications API or how to track a user's click on "x"?

Actually the question is quite simple, but I can not find the answer to it for quite a long time.
The site has a push notification. It is necessary to put an event listener on a click or action on this push and "understand" that "x" was pressed, that is, the push was closed.
granted, denied, default statuses I get, but they in no way tell me the status of the modal - whether it was closed or not...
For example:
1) The user is logged into the site.
Notification.permission will be default
2) I saw push clicked on the cross push closed
Notification.permission will be default
Actually the question is how to get the state of this push?
And how to determine that the user closed the push with a cross?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey, 2019-07-30
@azovl

Here is the solution:

Notification.requestPermission(function(status) {
        if(status === 'default') {
            console.log('Push closed!');
        }
    });

H
hzzzzl, 2019-07-30
@hzzzzl

maybe this will help or suggest ideas
https://stackoverflow.com/a/40348292

self.addEventListener('notificationclose', function(event) {
  // Do something as the result of the notification close
});

seems to be what you need, but I don’t know much about push notifications

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question