Update page automatically when accessing system

Asked

Viewed 567 times

5

I have a project, where I need the user to access the system, the system updates the page automatically, only once. I found how to do this from time to time( 5 in 5 seconds, for example), but I need to update only once.

To update every 5 seconds, I’m using this code in my controller:

Response.AddHeader("Refresh", "5");

Is there any way to adapt to upgrade only 1 time?

1 answer

5


With an HTTP header I find difficult, however you can use a script on your page:

window.onload = function() {
    if(!window.location.hash) {
        window.location = window.location + '#updateOnce';
        setTimeout(function () {
            window.location.reload();
        }, 5000);
    }
}
  • This does not imply that the page updates every 5 seconds, given the execution of the setTimeout()?

  • no, as the ! window.location.hash condition will only be satisfied once.

  • Just what I needed. I just changed the time to 1 second, it will bring me some kind of problem if the page takes time to load the client, or only updates after loading completely?

  • In this case it will only update 1 second after the page loads in full.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.