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
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
- Why not just use setTimeout and refresh page inside that to give time for second alert to show? – charlietfl Commented Jun 20, 2016 at 11:36
- I tried that, it works. but it isn't pretty. If the user clicks the ok button too early or too late it looks messy. I just want the page to refresh / go to the other page when the user clicks on the second OK @charlietfl – StabDev Commented Jun 20, 2016 at 11:40
- Isn't there something like onConfirm window.location.hrefetcetcetc ? @charlietfl – StabDev Commented Jun 20, 2016 at 11:44
- Create a demo. Not clear why what you have wouldn't work – charlietfl Commented Jun 20, 2016 at 11:45
2 Answers
Reset to default 2Try 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 = "/";
})
});
}
By adding a conditional statement & .then, you can redirect on the "OK" Button, and no need to implement the timer. I use this particular method for API calls.
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 = "/";
})
}
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745039480a4607725.html
评论列表(0条)