Sticky toastr onclick event of close button

21.4k views Asked by At

Is there a way I can perform an action after a user either clicks on the notification or clicks on the close button? At the moment I can do the first option using the options.onclick event. However I can not see how I can do this on the close button. Alternatively is there a way it could perform my action on the notification fading out?

toastr.options = {
    "closeButton": true,
    "timeOut": "0",
    "extendedTimeOut": "0"
};
toastr.options.onclick = function () {
    console.log("Notification clicked");
};
toastr.success("Success, Whooo!!");
3

There are 3 answers

0
Dave On BEST ANSWER

You can't do it nicely on click, because there is no callback. You could use a jquery live handler on the button.

About the notification after fading out, use this;

 toastr.options.onHidden = function() { console.log("onHide"); };
0
Kaan Öztürk On
toastr.options.onCloseClick = function() { console.log("You clicked close button!"); };

If you use onHidden instead of onCloseClick, when it times out it will be triggered even if you didn't click it.

0
Vikas kumar On

toastr.options.onCloseClick= function() { console.log("You clicked close button!"); };

its working for me