Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

refresh html page at certain interval for the first 5 minutes

Posted on 2011-02-24
6
Medium Priority
?
476 Views
Last Modified: 2012-05-11
How to refresh a html page at certain interval (e.g., every 10 seconds) for the first 5 minutes, after 5 minutes, stop refreshing.  I need code.  Thank you.
0
Comment
Question by:ToneElec
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 9

Expert Comment

by:CCSOFlag
ID: 34973631
you won't be able to do this unless you also integrate server-side scripting.  javascript does not have "session variables" that you can use to store the intervals.  You can easily set it up to refresh every 10 seconds.  The problem is on a refresh it would reset the timer, so there is no way to know when you hit the 5 minute mark unless you use server-side code.  You COULD also do it using a variable in the URL, but it's pretty ugly and would prolly be annoying to the user.
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 1000 total points
ID: 34976894
Javascrip have cookies, check this this :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
	window.onload = function() {
		var homer = getCookie("homer");
		var time = (new Date()).getTime();
		var oneMinute = 1000 * 60;
		var dt = 0;
		if(homer==null || homer=="") {
			document.cookie = "homer="+time;
		}
		else {
			dt = time - homer;
		}
		var m = dt / oneMinute;
		if(m<5) { // 5 minutes
			setTimeout("location.reload();", 10 * 1000); // 10 seconds
//			setTimeout("location.replace(location.href);", 10 * 1000);
//			setTimeout("location.href = location.href;", 10 * 1000);
		}
		else {
			document.cookie = "homer=; expires=Thu, 01-Jan-70 00:00:01 GMT;";
		}
		document.getElementById("homer").innerHTML = m;
	}

	function getCookie(c_name) {
		var i,x,y,ARRcookies=document.cookie.split(";");
		for(i=0;i<ARRcookies.length;i++) {
			x = ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
			y = ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
			x = x.replace(/^\s+|\s+$/g,"");
			if(x == c_name) {
				return unescape(y);
			}
		}
	}
</script>
</head>
<body>
<div id="homer"></div>
</body>
</html>

Open in new window

0
 
LVL 9

Expert Comment

by:mayank_joshi
ID: 34977801
Simply write this in <head> </head> section:-

<META HTTP-EQUIV="REFRESH" CONTENT="5">

this will refresh the page every 5 seconds.

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:CCSOFlag
ID: 34979889
you can also do it with cookies as mentioned, but cookies really should be avoided when possible, because a lot of people do not accept cookies.  
0
 

Author Comment

by:ToneElec
ID: 34981856
I tried leakim971's code, not bad code.  

But I have a question, is it possible that just refresh the page every 10 seconds when page was first opened up (pop up), not when the page is refreshed by user.  Right now, I found your code will refresh page every 10 seconds not only when it first opened, but also after user refresh the page manually.  Is this possible?  Thank you.

0
 

Author Comment

by:ToneElec
ID: 34982044
CCSOFlag;
I may have to let user accept cookies, as this will be on Intranet, implementation is more important now.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question