Refreshing Page for regular interval with javascript

Refreshing the html page for regular interval time with javascript

One of my friend asked to refresh the HTML page in his project that changes the stock rates every one minutes.i gave him simple solution like
example:1

7
8
9
10
11
12
13
<script>
var timer;
function refreshmypage(){
document.location=document.location.href;
}
timer=setTimeout(refreshmypage,60*1000);
</script>

Add above script after your HTML body content.Here setTimeout function takes two arguments one for function handler and other time to call the function,the time is in milliseconds.so i set to 60* 1000 i.e 60 seconds.
Example :2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<html>
<head>
<script type="text/javascript">
function load()
{
setTimeout("refresh()", 2000)
}
function refresh(){
window.location.reload()
load()
}
</script>
</head>
<body onload="load()">
</body>
</html>

Above example also can be used.
There is a deference between two examples.Example1 adds new history in every reload and Example2 reloads the page without browser history. i.e if you use example 1 ,user can see each reload by clicking browser’s back button.

2 thoughts on “Refreshing Page for regular interval with javascript

  1. I was just now looking for information about this when I discovered your blog post. I’m just visiting to say that I very much liked seeing this post, it’s very well written. Are you thinking of posting more on this? It seems like there is more material here for future posts.

  2. Thank you,
    Actually i am busy with my regular job and freelance job,even i will try to update the site in regular interval.if you have any queris you can ask here.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">