Search code examples
javascriptjqueryasp.netasp.net-mvcbootbox

Bootbox does the same for "ok" and "cancel" callback. It does the same for prompt as well


Bootbox closes and stays on the same page. It should redirect to a different page onClick and "ok" after that. It is an MVC application and redirects to Index action upon Click. The same code works for traditional Jquery confirm box.

$('.navbar, .navv').click(function(e) {
                e.preventDefault();

if(bootbox.confirm("Are you sure you want to leave the page!",
    function (result) {
        if (result === true) {
            return true; //should redirect to the Home page
        } else {
            return false; //Should stay in the same page
        }
    }));
});

Solution

  • Just remove the if loop around bootbox.confirm and return only if it is true.

    $('.navv').click(function(e) {
        e.preventDefault();
        bootbox.confirm("Are you sure you want to leave the page!",
        function (result) {        
            if(result) {
            window.open($('.navv').attr('href'));
          };
      });
    });
    

    Click on this link to see demo. https://jsfiddle.net/y3o8gamp/