SweetAlert 确认重定向

SweetAlert confirm redirect

我有这个功能可以重置游戏用户按下delete然后按下ok 再一次。

function confirmReset() {
  swal({   
          title: "Are you sure you want to reset your game?",   text: "You will not be able to recover your game!",
           type: "warning",   
           showCancelButton: true,   
           confirmButtonColor: "#DD6B55",   
           confirmButtonText: "Yes, delete it!",   
           closeOnConfirm: false 
         }, function(){   
          swal("Deleted!", "Your imaginary file has been deleted.", "success"), 
            function(){
              window.location.href = "includes/php/reset.php?naam=<?php echo $naam ?>";
            }
      });
}

它有效 如果 我在那个地方做 window.location.href 是第二个 swal('deleted'... 等等) 位于 ,但是如果我使用 second 函数 after 用户也会按下 OK它不会触发 window.location.href

试试这个代码:-

function confirmReset() {
  swal({   
          title: "Are you sure you want to reset your game?",   text: "You will not be able to recover your game!",
           type: "warning",   
           showCancelButton: true,   
           confirmButtonColor: "#DD6B55",   
           confirmButtonText: "Yes, delete it!",   
           closeOnConfirm: false 
         }, function(){   
            swal({
                title: "Deleted!",
                text: "Your imaginary file has been deleted.",
                type: "success",
                //timer: 3000
            }, 
            function(){
              window.location.href = "/";
            })
      });
}

通过添加条件语句&.then,您可以在“确定”按钮上重定向,无需实现计时器。我将此特定方法用于 API 调用。

function confirmReset() {
      swal({   
              title: "Are you sure you want to reset your game?",   
              text: "You will not be able to recover your game!",
              type: "warning",   
              showCancelButton: true,   
              confirmButtonColor: "#DD6B55",   
              confirmButtonText: "Yes, delete it!",   
              closeOnConfirm: false 
           }).then((result) => {
                if (result.isConfirmed) {
                 Swal.fire(
                  'Deleted!',
                  'Continue to .....',
                  'success'
                 ).then(function() {
                window.location = "/";
               })      
        }
    }