When this code runs, this alert is not displayed when the page reloads. I want to make the page reload after the alert appears.
// sweetalert framework
swal({
title: "Good job!",
text: "Profile Update Successfully!",
icon: "success",
button: "Okay!",
});
window.location.reload();
When this code runs, this alert is not displayed when the page reloads. I want to make the page reload after the alert appears.
// sweetalert framework
swal({
title: "Good job!",
text: "Profile Update Successfully!",
icon: "success",
button: "Okay!",
});
window.location.reload();
Share
Improve this question
edited 2 days ago
mplungjan
178k28 gold badges180 silver badges240 bronze badges
asked 2 days ago
udara lakshanudara lakshan
132 bronze badges
New contributor
udara lakshan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
- sweetalert.js.org/guides/#using-promises – Teemu Commented 2 days ago
2 Answers
Reset to default 1As far as i can get your question, you want the alert to show and then on confirmation you want the page to reload. For that you can simply follow the steps as mentioned here
You can update your code like
swal({
title: "Good job!",
text: "Profile Update Successfully!",
icon: "success",
button: "Okay!",
}).then(confirm => {
if (confirm) window.location.reload();
});
You can use Timeout.
swal({
title: "Good job!",
text: "Profile Update Successfully!",
icon: "success",
button: "Okay!",
});
setTimeout(function(){window.location.reload();},2000); /* auto reload after 2sec */