Page refresh after time

2

I made a page to sample data in real time, and I need to update in real time after 3 minutes.

I tried this code:

$(function() {
    setTimeout(function(){ location.reload(); }, 180000);
});

No results.

I do not know if I need to use (document) to perform the verification on the certainty of the entire document loaded, but within the ready fault I thought it would solve.

    
asked by anonymous 25.01.2017 / 20:01

3 answers

5

You can do this with HTML only :

<meta http-equiv="refresh" content="180">

Where content is the wait time (in seconds) to refresh

With javascript (you do not need jquery), try putting window :

setTimeout(function() {
  window.location.reload(1);
}, 180000); // 3 minutos
    
25.01.2017 / 20:03
2

You can do with Jquery too:

$(document).ready(function () {
    setTimeout(function () {
        window.location.reload(1);
    }, 5000); //tempo em milisegundos. Neste caso, o refresh vai acontecer de 5 em 5 segundos.
});

Remembering that for this to work, you need to have jquery included before the script declaration.

    
25.01.2017 / 20:05
2

Did you try to wait 10 minutes?

600000 milliseconds = 10 minutes.

$(function() {
    setTimeout(function(){ location.reload(); }, 600000); // 10 * 60 * 1000
});

If you want 3 minutes, try 180000 milliseconds.

$(function() {
    setTimeout(function(){ location.reload(); }, 180000); // 3 * 60 * 1000
});

In the example below you can see the same code being used after 3 seconds:

$(function() {
  setTimeout(function(){ 
    $("body").append(" o timeout aconteceu.");
  }, 3000);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
Três segundos depois...
</body>
    
25.01.2017 / 20:09