Example prevent close modal when press esc key SweetAlert

closeOnEsc: Decide whether the user should be able to dismiss the modal by hitting the ESC key, or not.

Default: closeOnEsc: true

Example:

 

<!DOCTYPE html>

<html>

    <body>

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

        <p>Example Alert use closeOnEsc</p>

 

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

        <script>

            function run() {

             swal("Can't close modal when press esc key",{

                closeOnEsc: false,

              });

            }

        </script>

    </body>

</html>

 

 Result:

 

 

Now you press esc key modal can't close.