最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do you try to reload the alert after it has been viewed? - Stack Overflow

programmeradmin2浏览0评论

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
Add a comment  | 

2 Answers 2

Reset to default 1

As 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 */
发布评论

评论列表(0)

  1. 暂无评论