3

I am currently using an html page for a webview within my iOS and Android apps. I don't want to update the native code and was wondering if I could just refresh the homepage which is index.html every 2 mins? Is it possible?

royhowie
  • 11,075
  • 14
  • 50
  • 67
  • 1
    `setInterval(function() { window.location.reload() }, 120000);` – Sterling Archer May 01 '15 at 21:21
  • 1
    Did you even google your question? I copypastad your title into google and [this question](http://stackoverflow.com/questions/19807665/auto-refresh-for-every-5-mins) was the 2nd result. – royhowie May 01 '15 at 21:35

4 Answers4

4

You can try to use like this:

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

or you can use setInterval like this:

setInterval(function() {
    window.location.reload();
}, 120000); 
royhowie
  • 11,075
  • 14
  • 50
  • 67
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
4

You can use:

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

The <meta http-equiv="refresh"> tag causes a web page to refresh automatically after a specified amount of time. Users generally don't expect automatic refreshes, so they can be disorienting. Refreshing also moves focus to the top of the page, which may frustrate or confuse users, particularly those who rely on screen readers or other assistive technologies.

Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
  • can i add 2 meta tags? or do i need to add it to my meta tag? –  May 01 '15 at 21:24
  • 1
    You can add many meta tags as you want as long as they're valid – Pedro Lobito May 01 '15 at 21:25
  • Refreshing with meta tags is fine for regular websites. But will not work on a lot of TVs using the default television browser. If your use is to have the page displayed on a television you should use the JavaScript way: setInterval(function() { window.location.reload(); }, 120000); – VMeijer Jul 13 '20 at 15:01
2

use this

  setTimeout(function(){
       window.location.reload(1);
    }, 120000);

EDIT Put this in head

<script>
      setTimeout(function(){
           window.location.reload(1);
        }, 120000);
</script>

EDIT

to attach this function only when page is ready use this

<script>
     $('document').ready(function(){
        setTimeout(function(){
           window.location.reload(1);
        }, 120000);
     });
</script>
vasilenicusor
  • 2,023
  • 1
  • 21
  • 37
  • can you explain with a chunk of my code? i have no idea where to place it? –  May 01 '15 at 21:24
  • 1
    @vasilenicusor kudos for the parameter of the reload function. I did't know it was that easy to avoid the cache. – NiloVelez May 01 '15 at 21:30
  • from http://www.w3schools.com/jsref/met_loc_reload.asp , by default, the reload() method reloads the page from the cache, but you can force it to reload the page from the server by setting the forceGet parameter to true: location.reload(true). – vasilenicusor May 01 '15 at 21:40
0

You can Put meta tag before html start e.g.

<meta http-equiv="refresh" content="120">
  <html> 
    <head>
      <meta charset="UTF-8">    
        <title>Mart</title>