0

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"
    }
  })
sallf
  • 2,583
  • 3
  • 19
  • 24
amii
  • 3
  • 4
  • Does this answer your question? [How to redirect page after click on Ok button on sweet alert?](https://stackoverflow.com/questions/37358423/how-to-redirect-page-after-click-on-ok-button-on-sweet-alert) – wlh Feb 16 '20 at 19:56
  • yes it does. thank you – amii Feb 17 '20 at 06:10

2 Answers2

0

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";
  }
});
Aluminium Shek
  • 306
  • 1
  • 5
  • thank you.it works when i do: 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) { window.location.href = "trial.php"; } }); – amii Feb 16 '20 at 18:59
0

swal({ title: "test", text: "testing", buttons: { cancel: true, confirm: "continue" } }).then((value) => { if (value) { window.location.href = "trial.php"; } });
amii
  • 3
  • 4