sweetalert2 ok button event code example
Example 1: sweet alert after click ok redirect
swal({
title: "Wow!",
text: "Message!",
type: "success"
}).then(function() {
window.location = "redirectURL";
});
Example 2: sweet alert 2 do action on confirm
Swal.fire({
title: 'Do you want to save the changes?',
showDenyButton: true, showCancelButton: true,
confirmButtonText: `Save`,
denyButtonText: `Don't save`,
}).then((result) => {
/* Read more about isConfirmed, isDenied below */
if (result.isConfirmed) {
Swal.fire('Saved!', '', 'success')
} else if (result.isDenied) {
Swal.fire('Changes are not saved', '', 'info')
}
});
Example 3: sweetalert close on custom button click
swal.close()