Search code examples
javascriptsweetalertsweetalert2

Don't hide SweetAlert2 when another is launched


I am using SweetAlert2. I want to show one alert behind another one, so that when the user clicks on the "OK" button, the other alert is shown behind it.


Solution

  • Many demos/examples on configuration docs: https://sweetalert2.github.io/#configuration
    Add it as a Promise then to launch after the current SweetAlert.

    Swal.fire("1").then(x =>
      Swal.fire("2").then( x =>
        x.value && Swal.fire("3")))
        // check x.value, only fire "3" if button clicked
    .then( x =>
      Swal.queue(["5","6","7"]))
      // you can also use queue to queue up alerts
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>