Prevent SweetAlert to be closed on clicking outside the popup window

前端 未结 13 801
不知归路
不知归路 2021-02-01 04:40

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

相关标签:
13条回答
  • 2021-02-01 04:44

    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
        }
    })
    
    0 讨论(0)
  • 2021-02-01 04:49

    For sweetalert version < 2

    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")
             }
        })
    
    0 讨论(0)
  • 2021-02-01 04:51

    You can set this property:

    allowOutsideClick: true
    
    0 讨论(0)
  • 2021-02-01 04:55

    If the answers above do not work for you try:

    closeOnClickOutside: false

    0 讨论(0)
  • 2021-02-01 04:55

    For latest version it is

    allowOutsideClick: false
    
    0 讨论(0)
  • 2021-02-01 04:56

    For SweetAlert 2:

    allowOutsideClick: false
    

    and version 3 and some below version 2:

    closeOnClickOutside: false
    
    0 讨论(0)
提交回复
热议问题