Closed garubi closed 6 years ago
@scream4ik thank you, I'm going to try it
@scream4ik I checked the code and the docs but still I can't understand how to use 'tag' to prevent duplicate notification on the screen.
I added tag: 'mytag'
but still I get duplicate notification.
moreover, it looks like the 'tag' is only for desktop notifications and not for "in browser" notification
I'm sorry to bother you, but can you show me a practical example of how to avoid duplicate notifications? Thank you very much!!
My js:
function desktop_notify(msg) {
(new PNotify({
title: msg.pnotify_title,
text: msg.pnotify_text,
hide: false,
buttons: {
sticker: false
},
desktop: {
desktop: true,
tag: msg.pnotify_tag
}
})).get().click(function(e) {
if ($('.ui-pnotify-closer, .ui-pnotify-sticker, .ui-pnotify-closer *, .ui-pnotify-sticker *').is(e.target)) return;
if (msg.pnotify_url)
window.open(msg.pnotify_url, '_blank')
});
}
From backend i generate unique tag (msg.pnotify_tag)
I test it only for desktop notifications
Wow, thank you for the fast answer! ;-)
I see... for the desktop notification now I understand.
In the meantime for the "in browser" notification i solved siply adding a specific class to the notification(with addclass
), then checking if an element with that clas is already present. If present I don't add the new notification:
`
if($('.newreq').length <1){
var notice = new PNotify({
title: 'My Title',
text: 'My message',
type: 'info',
addclass: 'my_unique_class',
hide: false
});
`
For PNotify 3, you can use PNotify.removeAll()
before you open a notice. For PNotify 4, the history module now has a maxInStack
option to do what you want.
I would like to avoid that a notification will be displayed if another notification is already on screen... How can I check it? I looked in the examples but haven't found anything ...
Thank you Stefano