how to add a callback to jquery plugin function

124 Views Asked by At

I am using a jquery plugin for alerts given below:-

 function alertWithNewWindow(title, content, icon, newWindow) {
            $.alert.open({
                title: title,
                content: content,                   
                icon: icon,                   
                draggable: true
            });
        }

I want to add a callback to above function so that when user click on "ok" button of alert-box then page will redirect to the given path.

  $(window.location.replace(newWindow));

I have tried below code but its not redirecting.

   function alertWithNewWindow(title, content, icon, newWindow) {
            $.alert.open({
                title: title,
                content: content,                
                icon: icon,                  
                draggable: true
            }, function () {
                $(window.location.replace(newWindow));
            }
            );
        }
1

There are 1 best solutions below

0
On BEST ANSWER

I am guessing you are using this plugin.

After reading the Callback doc section I think this code should work out for you:

  function alertWithNewWindow(title, content, icon, newWindow) {
            $.alert.open({
                title: title,
                content: content,
                align: 'center',
                icon: icon,
                maxHeight: 160,
                draggable: true,
                callback: function(){
                       $(window.location.replace(newWindow));
                   } 
            );
        }