-1

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

BNJ
  • 108
  • 1
  • 8
  • Just use `location.href = new value`. There's no reason to put it in a jQuery object. However you're trying to put that into an object (`{}`) which isn't right. bootbox may have some way to bind callbacks for the individual buttons – Taplar Apr 23 '18 at 17:31
  • it not worked with location.href – BNJ Apr 23 '18 at 17:35

1 Answers1

1

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';
        }
    }
Taplar
  • 24,788
  • 4
  • 22
  • 35