javascriptjquerybootstrap-dialog

How to prevent script execution after BootstrapDialog opens?


I am using BootstrapDialog for showing some alerts.

    BootstrapDialog.alert({
          type:  BootstrapDialog.TYPE_DANGER,
          title: 'Oops! ',
          message: 'Error, occured',
          buttons: [{
              label: 'Ok'

          }]
      });
    window.location.replace("http://example.com");

I want that if dialog opens it doesn't redirect to another page. It should only redirect if a user clicks "OK" button, as if I were using alert in javascript.


Solution

  • You should attach the window.location code inside the buttons attribute. Try doing this:

    BootstrapDialog.show({
        type:  BootstrapDialog.TYPE_DANGER,
        title: 'Oops! ',
        message: 'Error, occured',
        buttons: [{
            label: 'Ok',
            action: function(dialog) {
                window.location.replace("http://example.com");
            }
        }]
    });