PDA

View Full Version : Refresh screen dropdown box code


Lonewolf_tj
01-10-2006, 04:22 PM
Hello all, what a popular place to be :D

Just wandering if anyone can assist me with the follow issue I'm having with my site?

I've got a link to my forum on my home page and want to write a piece of code that will give the viewer an option in the form of a dropdown box to refresh the page automatically every preset minutes eg: reload page every __ minutes.

I'm looking for something like: -

Don't reload page
Reload every minute
Reload every 2 minutes

and so on including 5, 10, 15 and 30 mins.

http://myweb.tiscali.co.uk/terryj

Any assistance with this would be great :)

-i-dont-know-
01-10-2006, 04:28 PM
Welcome to the forums! Here is some code that will refresh you page every 2 mins auotmatically:

<script type="text/javascript">
<!--
function refresh() { location.href=this.location;}
//-->
window.setInterval('refresh()',120000);
</script>

Im not to sure about the drop down box bit but hope this helps!
You can change the refresh interval by editing the 120000.

Lonewolf_tj
01-10-2006, 04:58 PM
The drop down is more for a choice thing than anything else as the site does refresh every 15 mins at present (erm, probably depending on browser lol), it's more for that personal touch i'm after.

Thanks for the code though, I will keep a note of it for future ref as it looks different to mine, every little helps at this stage as I'm fairly new to the web design game.

_Aerospace_Eng_
01-10-2006, 08:03 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Reload page, remember with cookie</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
var thecookie = readCookie('doreload');
function isCookie(){
if(thecookie == "60000"){
document.forms[0].reloadme.options[1].selected=true;
}
else if(thecookie == "120000"){
document.forms[0].reloadme.options[2].selected=true;
}
else if(thecookie == "300000"){
document.forms[0].reloadme.options[3].selected=true;
}
else if(thecookie == "600000"){
document.forms[0].reloadme.options[4].selected=true;
}
else if(thecookie == "900000"){
document.forms[0].reloadme.options[5].selected=true;
}
else if(thecookie == "1800000"){
document.forms[0].reloadme.options[6].selected=true;
}
else {
document.forms[0].reloadme.options[0].selected=true;
}
if(thecookie != null){
startIt(thecookie);
}
}
function startIt(thetime){
reloader=setInterval("reloadPage()",thetime);
createCookie('doreload',thetime,9999);
}
function reloadPage(){
window.location=this.location;
}
function createCookie(name,value,days){
if(days){
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else {
var expires = "";
}
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name){
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++){
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

function eraseCookie(name){
createCookie(name,"",-1);
if(thecookie != null){
clearInterval(reloader);
}
alert('The cookie has been cleared and page will stop reloading');
document.forms[0].reloadme.options[0].selected=true;
}
window.onload=isCookie;
</script>
</head>
<body>
<form action="#" method="post">
<div>
The refresh rate will be remembered when the page reloads.
<select name="reloadme" onchange="startIt(this.value)">
<option value="null">Choose a refresh rate</option>
<option value="60000">1 Minute</option>
<option value="120000">2 Minutes</option>
<option value="300000">5 Minutes</option>
<option value="600000">10 Minutes</option>
<option value="900000">15 Minutes</option>
<option value="1800000">30 Minutes</option>
</select>
<input type="button" onclick="eraseCookie('doreload')" value="Stop Reloading">
</div>
</form>
</body>
</html>

Lonewolf_tj
01-12-2006, 06:00 PM
It appears to be work great.

Thanks for your help I had no idea it would take so many lines of code.

Truly greatful.