Search code examples
jqueryhtmlbootbox

bootbox how to redirect on href link


i am new in jquery and bootbox i want to add an action to each button alert of the confirmation so if the selected button is yes then i want to redirect in a link for exemple

<script  type="text/javascript">
$(function() {

bootbox.confirm({
message: "click yes to redirect google",
buttons: {
    confirm: {
        label: 'Yes',
        className: 'btn-success'
        $(location).attr('href',"http://www.google.com/");

    },
    cancel: {
        label: 'No',
        className: 'btn-danger'
    }
},
callback: function (result) {
    console.log('This was logged in the callback: ' + result);
}
});
});
</script>

i'used $(location).attr('href',"http://www.google.com/"); but it not worked

thank you


Solution

  • Example from the documentation. http://bootboxjs.com/documentation.html#bb-confirm-dialog

    bootbox.confirm({ 
        size: "small",
        message: "Are you sure?", 
        callback: function(result){ /* result is a boolean; true = OK, false = Cancel*/ }
    })
    

    So you can just use that

        callback: function(result) {
            if (result === true) {
                location.href = 'http://www.google.com';
            }
        }