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?
Asked
Active
Viewed 1.7k times
3
-
1`setInterval(function() { window.location.reload() }, 120000);` – Sterling Archer May 01 '15 at 21:21
-
1Did 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 Answers
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
-
how do i setinterval? can you explain with a chunk of my code? I have no idea how js-html code works? – May 01 '15 at 21:24
-
1[Documentation is helpful](https://developer.mozilla.org/en-US/docs/Web/API/Location/reload) – Sterling Archer May 01 '15 at 21:25
-
setInterval has no meaning in this context, since the page is refreshed, the timer will only ever be called once... – Madara's Ghost May 01 '15 at 21:40
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
-
-
1
-
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
-
-
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>

Dr Manish Lataa-Manohar Joshi
- 2,380
- 5
- 17
- 38