StabDev StabDev - 5 months ago 40
Javascript Question

SweetAlert confirm redirect

I've got this function to reset the game after the user presses delete and then presses ok again.

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 ?>";
}
});
}


it works if i do the
window.location.href
at the place were the second swal('deleted'... etc) is at , but if i use a second function after the user preses OK aswell it wont fire the
window.location.href

Answer

Try this code :-

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 = "/";
            })
      });
}
Comments