Example use timer of SweetAlert

Closes the modal after a certain amount of time (specified in ms). Useful to combine with buttons:false.

Example: Use timer close modal

 

<!DOCTYPE html>

<html>

    <body>

        <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>

        <p>Example Alert use timer</p>

 

        <button onclick="run()">Run</button>

 

        <script>

            function run() {

               swal("This modal will disappear soon!", {

                  buttons: false,

                  timer: 3000,

                });

            }

        </script>

    </body>

</html>

 

Result:

 

 

Modal will close after 3 seconds