I am using Sweet Alert for a popup on my product view in an E-commerce Application with two buttons: one for going on cart View and another for reloading the vi
Use backdrop:true
with the allowOutsideClick: false
as following below. It worked for me.
swal({
backdrop:true,
allowOutsideClick: false,
title:'Warning!',
text:'Do you want to delete records?',
type:'warning',
showCancelButton: 0,
confirmButtonText: 'OK',
}).then(function(e) {
if (e.value) {
//do what you want
}
})
swal(
"Records will be deleted permanently.", //title
"Do you want to delete records?", //text
"warning", //icon
{
closeOnClickOutside: false, // prevent close on click anywhere/outside
buttons: ["No", "Yes"], //with custom label
dangerMode: true,
}
).then(ok => {
if (ok) {
console.log("deleted")
}
else {
console.log("not deleted")
}
})
You can set this property:
allowOutsideClick: true
If the answers above do not work for you try:
closeOnClickOutside: false
For latest version it is
allowOutsideClick: false
For SweetAlert 2:
allowOutsideClick: false
and version 3 and some below version 2:
closeOnClickOutside: false