i need go to another page after click at ok or error button...my code:
i use a $(document) because i need show the error when the page is loaded
pls give me a hand ;)
i think this can be done using location.href = 'http://google.com'
this should be called at ok / error button click handler;
As @technofreaky said, you can redirect using JavaScript. Here's a similar example: https://github.com/t4t5/sweetalert/issues/168
i can solve it :)
only use window.location.href .. here is the code:
$(document).ready(function() {
swal({
title: "Error",
text: "wrong user or password",
type: "error"
},
function(){
window.location.href = 'login.html';
});
});
Thank's for help me
@fabianchoxD Good Job !
I need to bind a html page within sweet alert. so that when my sweet alert triggered it should show the html page in its body.
how can i do the alert when user is trying to close browser/tab with SweetAlert? Please help me out..
@fabianchoxD thanks, it works.
anyone have any idea about the callback function/event triggered on click of OK
button genereated using persistant()
function?
Alert::success('Success Message', 'Optional Title')->persistent("Ok");
@fabianchoxD thank you for the solution but it did not work for me. I was able to resolve this issue like this:
swal({
title: "Success!",
text: response.scriptstatus,
type: "success"
}).then(function() {
// Redirect the user
window.location.href = "new_url.html";
console.log('The Ok Button was clicked.');
});
@cnchg many thanks, it's work for me!!!
If you also have a "Cancel" button in your modal, you'll want to confirm that the "OK" button was indeed pressed:
swal({...}).then(okay => {
if (okay) {
window.location.href = "...";
}
});
swal({
icon: "error",
title: "¡Error!",
showConfirmButton: true,
confirmButtonText: "Cerrar",
closeOnConfirm: false
}). then(function(result){
window.location = "WEREYOUWANTTOGO";
})
This is my solution for this issue!
function MesajUyari($mesaj,$text,$icon,$sure,$url){
echo"
swal({
title:\"$mesaj\",
text:'$text',
icon:'$icon',
button:'Kapat'
});
";
header("Refresh: $sure; url=$url");
//location.href = 'http://www.alokatalog.com/'
//$gidecekSiteAdres= header('location:'.$_SERVER['HTTP_REFERER']);
}
MesajUyari("Proje Oluşturma Başarılı","Yönlendiriliyorsunuz
Lütfen Bekleyin","success",3,"Sayfa.php");/
@fabianchoxD thank you for the solution but it did not work for me. I was able to resolve this issue like this:
swal({
title: "Success!",
text: response.scriptstatus,
type: "success"
}).then(function() {
// Redirect the user
window.location.href = "new_url.html";
console.log('The Ok Button was clicked.');
});
Thanks!! It worked!!
Mine is redirecting to the page directly without even showing the Alert message. Am using Chrome.
swal({
title: "App",
text: "Error: Invalid Credentials, try again !",
icon: "error",
closeOnConfirm: false
}).then(
function () {
window.location.href = 'index.html';
}
);
Hi, I'm trying to make swal disappear after 5 seconds so I put a timer: 5000
but when the timer is done, even if the user didn't click the button, it goes to another page. I want to the user to stay on the page if he didn't click the button on swal. Here's my code:
Swal.fire({
html: "Your tip has been published.",
icon: 'warning',
showCancelButton: false,
confirmButtonText: "See tip",
timer: 5000,
customClass: {
container: 'custom-alert',
popup: 'published-tip',
actions: 'actions-btn'
},
}).then(function() {
window.location = "/" + data.username;
});
Most helpful comment
i can solve it :)
only use window.location.href .. here is the code:
});
Thank's for help me