Automatic Refresh

Problems not covered by any other forum topic.

Moderator: davidyin

Locked
User avatar
tyman00
Members
Members
Posts: 42
Joined: Tue Dec 20, 2005 12:59 pm
Location: Mandan, ND
Contact:

Automatic Refresh

Post by tyman00 »

The users of our I/O board wanted to have the board automatically refresh so the status of others would be updated periodically without having to maually refresh the page.

After using a few different scripts found from Javascriptkit.com I compiled the following code. I thought someone else might want to use it.

Under the <HEAD> tag in default.asp Place this code:

Code: Select all

<script type="text/javascript">
<!-- hide from old browsers



function formHandler(form1){
var value = document.form1.site.options[document.form1.site.selectedIndex].value;
window.location.href = "default.asp?time="+value;
}

function getValue(varname)
{
  // First, we load the URL into a variable
  var url = window.location.href;

  // Next, split the url by the ?
  var qparts = url.split("?");

  // Check that there is a querystring, return "" if not
  if (qparts.length == 0)
  {
    return "";
  }

  // Then find the querystring, everything after the ?
  var query = qparts[1];

  // Split the query string into variables (separates by &s)
  var vars = query.split("&");

  // Initialize the value with "" as default
  var value = "";

  // Iterate through vars, checking each one for varname
  for (i=0;i<vars.length;i++)
  {
    // Split the variable by =, which splits name and value
    var parts = vars[i].split("=");
    
    // Check if the correct variable
    if (parts[0] == varname)
    {
      // Load value into variable
      value = parts[1];

      // End the loop
      break;
    }
  }
  
  // Convert escape code
  value = unescape(value);

  // Convert "+"s to " "s
  value.replace(/\+/g," ");

  // Return the value
  return value;
}
// The time out value is set to be 10,000 milli-seconds (or 10 seconds)
var time = getValue("time"); 
//setTimeout(' document.location=document.location' ,time*1000);
  var tempTime = time;
  
var parselimit=time;
function begintimer(){
if (!document.images)
return
if (parselimit==1)
window.location.reload() //="document.location"
else{ 
parselimit-=1
curmin=Math.floor(parselimit/60)
cursec=parselimit%60
if (curmin!=0)
curtime=curmin+" minutes and "+cursec+" seconds left till refresh"
else
curtime=cursec+" seconds left till refresh"
window.status=curtime
setTimeout("begintimer()",1000)
}
}
// end hide -->

</script>
Then somewhere in the <BODY> tag (I placed it in the unordered list for the navigation) place this code:

Code: Select all

<script language="JavaScript"> 
if (tempTime==15){
document.write('<form name="form1">');
document.write('<select name="site" size=1 onChange="javascript:formHandler()">');
document.write('<option selected value="15">15 Seconds');
document.write('<option  value="30">30 Seconds');
document.write('<option value="60">1 minute');
document.write('<option value="120">2 minutes');
document.write('<option value="300">5 minutes');
document.write('</select>');
document.write('</form>');
}

else if (tempTime==30){
document.write('<form name="form1">');
document.write('<select name="site" size=1 onChange="javascript:formHandler()">');
document.write('<option value="15">15 Seconds');
document.write('<option selected value="30">30 Seconds');
document.write('<option value="60">1 minute');
document.write('<option value="120">2 minutes');
document.write('<option value="300">5 minutes');
document.write('</select>');
document.write('</form>');
}

else if (tempTime==60){
document.write('<form name="form1">');
document.write('<select name="site" size=1 onChange="javascript:formHandler()">');
document.write('<option value="15">15 Seconds');
document.write('<option value="30">30 Seconds');
document.write('<option selected value="60">1 minute');
document.write('<option value="120">2 minutes');
document.write('<option value="300">5 minutes');
document.write('</select>');
document.write('</form>');
}

else if (tempTime==120){
document.write('<form name="form1">');
document.write('<select name="site" size=1 onChange="javascript:formHandler()">');
document.write('<option value="15">15 Seconds');
document.write('<option value="30">30 Seconds');
document.write('<option value="60">1 minute');
document.write('<option selected value="120">2 minutes');
document.write('<option value="300">5 minutes');
document.write('</select>');
document.write('</form>');
}

else if (tempTime==300){
document.write('<form name="form1">');
document.write('<select name="site" size=1 onChange="javascript:formHandler()">');
document.write('<option value="15">15 Seconds');
document.write('<option  value="30">30 Seconds');
document.write('<option value="60">1 minute');
document.write('<option value="120">2 minutes');
document.write('<option selected value="300">5 minutes');
document.write('</select>');
document.write('</form>');
}

else {
document.write('<form name="form1">');
document.write('<select name="site" size=1 onChange="javascript:formHandler()">');
document.write('<option selected>Time not in list!');
document.write('<option value="15">15 Seconds');
document.write('<option  value="30">30 Seconds');
document.write('<option value="60">1 minute');
document.write('<option value="120">2 minutes');
document.write('<option value="300">5 minutes');
document.write('</select>');
document.write('</form>');
}
</script>
I understand this is quite long and redundant, but I wanted the drop down box to show the time value the user had selected. If that does not matter to you use this code instead to use a smaller file size:

Code: Select all

<form name="form1">
<select name="site" size=1 onChange="javascript:formHandler()">
<option value="15">15 Seconds');
<option  value="30">30 Seconds
<option value="60">1 minute
<option value="120">2 minutes
<option value="300">5 minutes
</select>
</form>
I used the onChange action for the drop down menu. So it will refresh the page and set the time right away when a user selects the time.

You could also use this instead of the onChange value (but be sure to remove the onChange action from the selection menu):
<input type=button value="Refresh Now" onClick="formHandler()">

I also went further and changed every link in default.asp to pass the selected time when ever they were going to be redirected to default.asp. (I.E. Home, The sorting links) That required a bit of javascript that had to be entered for each link. That is quite a bit to be posting here. If someone has a little background in Javascript and wants some pointers reply here and I will get in contact with you.

I know the code is not clean, but we are running this on our Intranet where I tested it and I know it can be run. I do not claim this will work for you or be fast, but I thought maybe it will be of help to others.

I post this code assuming that you have some experience in javascript, even then you might be able to get by without any. 8)
Last edited by tyman00 on Tue Dec 20, 2005 1:30 pm, edited 1 time in total.
User avatar
tyman00
Members
Members
Posts: 42
Joined: Tue Dec 20, 2005 12:59 pm
Location: Mandan, ND
Contact:

Post by tyman00 »

I believe I might have put this in the wrong forum :roll:

Feel free to move it if needed.
User avatar
davidyin
Members
Members
Posts: 192
Joined: Wed Apr 27, 2005 10:50 pm
Location: Burnaby

Pentacle In-Out board has auto-refresh

Post by davidyin »

The interval of auto-refresh of homepage is 450second, or 7.5 minutes.

If you find your In-Out board is not autorefresh, open Default.asp.
Find
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
After it paste following code:
<meta http-equiv="Refresh" content="450" />
Locked