Search code examples
javascripthtmlcssfunctionalert

linking a button to another page in SweetAlert


am i using sweet alert and i have 2 buttons; one is cancel button and the another one is continue button. i want to link the 'continue' button to another page that is 'trial.php'. how can i proceed with this? below is code i've tried:

if(m <= 2){
  swal({
    title:"dataset file is: "+  ""+size2 +"Mb",
    text: "a cluster of 1 node will be required for processing",
    buttons: {
      cancel: true,
      confirm: "continue"
    }
  })


Solution

  • Use .then() to watch the value of the pressed button and if the value is "continue", use window.location.href to redirect user to another page:

    swal({
      title: "dataset file is: " + "" + size2 + "Mb",
      text: "a cluster of 1 node will be required for processing",
      buttons: {
        cancel: true,
        confirm: "continue"
      }
    }).then((value) => {
      if (value === "continue") {
        window.location.href = "trial.php";
      }
    });