sciactive / pnotify

Beautiful JavaScript notifications with Web Notifications support.
https://sciactive.com/pnotify/
Apache License 2.0
3.65k stars 513 forks source link

Close a desktop notification #264

Closed PranKe01 closed 6 years ago

PranKe01 commented 8 years ago

Hi, I want to close a desktop notification when I click on it. How can I do that?

Here is my "shortened" code:

` new PNotify({ delay: 8000, desktop: { desktop: true, tag: uniqueTag } }).get().click(function (e) { if ($(e.target).is('.ui-pnotify-closer, .ui-pnotify-sticker, .ui-pnotify-closer , .ui-pnotify-sticker ')) { return; }

        if (PNotify.desktop.checkPermission() === 0) {
            $(this).remove(); // That does not close the desktop notification :(
        } else if ($(e.target).is('a')) {
            $(this).remove(); // That does close a html-notification
        }
    });`
jshah4517 commented 7 years ago

I don't know if you still need help with this, but maybe it'll help someone else. I was able to get it to close by with the following code (closes on click):

var notify = new PNotify({ ... });

// Close desktop notification on click
notify.get().click(function() {
    notify.desktop.close();
});
satejrajam30 commented 6 years ago

@jshah4517 : How can we close the notification in react?

zhuber commented 6 years ago

@satejrajam30 thanks for catching this issue. This was actually an issue with the React package, not the PNotify library. I've since fixed it and you should be able to simply update react-pnotify to see that changes working.

Patched in PR#2: https://github.com/zhuber/react-pnotify/pull/2

alekhyageddam commented 4 years ago

Hi, I'm still facing an issue with closing the pnotify notification. I'm using bootstrap3 for styling.

My closer button looks like this: image

I have a function called displayErrorMessage = function(msg){ var error = new PNotify({

}); }.

outside this function, in the same file, i have another function called eventTriggers. within this function, I have written: var errorMsg = nx.common.displayErrorMessage(); $('.ui-pnotify-closer*').click(function(){ errorMsg.remove(); });

My main aim is to remove the notif upon clicking the 'X' button. I've read some places that if you have history attribute in the PNotify instantiation, then closing the button may not work. I'm not entirely sure though, can someone help me with this.

Thanks!