Search code examples
javascriptalert

How do you try to reload the alert after it has been viewed?


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();

Solution

  • 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();
    });