Angularjs notification showing twice if on 2 browser tabs

558 views Asked by At

I am using angular-web-notification . My problem is that if I open 2 browser tabs and then the messages are received, I get to see two instances of notifications shown.

Below is the reference code.

    webNotification.showNotification(title, {
        body: body,
        onClick: function onNotificationClicked() {
            console.log('Notification clicked.');
        },
        icon: 'icon.png'
    }, function onShow(error, hide) {
        if (error) {
            console.log('Unable to show notification: ' + error.message);
        } else {
            console.log('Notification Shown.');
        }
    });

Do you have any ideas?

2

There are 2 answers

3
Aian On BEST ANSWER

To prevent any duplicate notification use Tag

Notification.tag The ID of the notification https://developer.mozilla.org/en-US/docs/Web/API/notification

 webNotification.showNotification(title, {
        body: body,
        tag:"some custom unique tag per notification"
        onClick: function onNotificationClicked() {
            console.log('Notification clicked.');
        },
        icon: 'icon.png'
    }, function onShow(error, hide) {
        if (error) {
            console.log('Unable to show notification: ' + error.message);
        } else {
            console.log('Notification Shown.');
        }
    });
3
Private Mail On

In my case i had got the push notification twice, but i solved that before. At the moment, i have one question for you now, do you use fcm ?