Trying to do simple stuff. I do not want to close popup until user click on confirm button (I turned off this option but popup is still closing). Here is my code:
sweetAlert({
title: "Hello",
text: "<button type='button' class='btn btn-fb fb-share'>Share on Facebook</button>",
type: null,
confirmButtonText: "Close",
html: true,
closeOnConfirm: false, //It does close the popup when I click on close button
closeOnCancel: false,
allowOutsideClick: false
});
$(document).on( "click",".fb-share", function(e){
//here sweet alert closes when I press this button.
openFbPopup();
});
How do I prevent closing sweet alert?
I also seem to be having issues with this. Even when I set allowOutsideClick to false, it is still dismissible.
@moazam1 For your specific case, you need to do a callback as an additional parameter after the options object:
sweetAlert({
title: "Hello",
text: "<button type='button' class='btn btn-fb fb-share'>Share on Facebook</button>",
type: null,
confirmButtonText: "Close",
html: true,
closeOnConfirm: false, //It does close the popup when I click on close button
closeOnCancel: false,
allowOutsideClick: false
}, function () {});
$(document).on( "click",".fb-share", function(e){
//here sweet alert closes when I press this button.
openFbPopup();
});
It doesn't need to do anything, but using a function like:
function (isConfirm) {
// ... Rest of code
}
Allows you to respond manually and do something else.
Makes sense, as if you don't have a handler, how are you going to close the alert otherwise.
If you are using an anchor tag, just remove the href="", because it redirects you to the same page. thats why the alert closed itself
I know this is late, but might help somebody in the future
@moazam1 The option has been changed to
swal({
closeOnClickOutside: false,
});
This didn't worked.
@moazam1 thanks it did worked for me
@moazam1
$(document).on( "click",".fb-share", function(e){
here you have to add e.preventDefault();
openFbPopup();
it worked for me.
});
Most helpful comment
I know this is late, but might help somebody in the future
@moazam1 The option has been changed to
https://sweetalert.js.org/docs/#closeonclickoutside