Click to See Complete Forum and Search --> : Refresh page every 24 hours?
jjski
05-12-2003, 03:46 PM
I am not a programmer, so I am looking for a simple script to put into a page that will refresh the page at a given time: (example: 12:05 am refresh page)
Any help is muchly appreciated
Thanks
Are you talking about updating the page? Something like at 12:05 add new content?
jjski
05-12-2003, 03:57 PM
I have an html page that runs a script to change an image at the beginning of every day. This page will never be closed, so I need a script that will refresh at 12:00 am every day, so as people will see the change in images.
angrytuna
05-12-2003, 05:06 PM
Perhaps something like this?
<html>
<head>
<title>Image Swapping by day</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<script>
date1 = new Date();
date1.setTime(0);
date2 = new Date();
difftime = (date2-date1)/60/60/24;
picArray = new Array("pic1.jpg", "pic2.jpg", "pic3.jpg");
document.getElementsByName("myimage").src = picArray[Math.round(difftime%3)];
</script>
<img name="myimage" src="picdefault.jpg">
</body>
</html>
"picarray" is an array of all your pictures. You'll need to change the mod value to the amount of pictures you have.
Hope this helps?
~AT
jjski
05-12-2003, 05:10 PM
Thanks for the script, but I already have one that will change the images. I need a script that will just refresh the page at 12:00 am. The reason for this is that the page will be displayed on a computer at all times. There will be no one there to refresh the page, hence the images will not change until the page is refreshed.
Which do you want to use JavaScript, or HTML? In any case, you should keep the Pragma META tag in your HTML code.
HTML:
<meta name="Refresh" content="86400">
<meta name="Pragma" content="no-cache;">
JavaScript:
<script language="javascript" type="text/javascript">
setTimeout("location.reload()", 86400);
</script>
jjski
05-12-2003, 05:35 PM
Will either of those refresh at 12:00 am, or are they just a set number of seconds? If I just have seconds, then I would have to load the page at exactly 12:00 am.
LOL, my bad. In this case, you'd use a combination of the two:
<meta name="Pragma" content="no-cache;">
<script language="javascript" type="text/javascript">
function reloadAt12(){
var d = new Date();
var time = d.getHours();
if(time==21){location.reload();}
}
window.setInterval("reloadAt12()", 1000);
</script>
khalidali63
05-13-2003, 12:48 AM
Originally posted by jjski
There will be no one there to refresh the page, hence the images will not change until the page is refreshed.
As you mentioned earlier that you have th escript that changes the image,if it does the job correctly,the image must have been changed,therefore you will not need to refresh or reload thepage at a certain hour,because the image would have been changed by the script anyways...And if you must refresh for whatsoever reasons,meta tags are probably a better options.
jjski
05-13-2003, 08:21 AM
The html page will not be online, rather it will be used as a sort of kiosk. This is the reason that the page needs to refresh itself. If I use meta tags, then it will only refresh after the amount of seconds that I specify. This will not work unless I initially launch the page at 12:00 am. If I launched it at say 3:00 pm, it will only refresh at 3:00.
Is there a way to just use the new Date function combined with a refresh?
Here is the script that I am using (I think I got it from javascript.net) and it works great other than the refresh part:
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Jeff Harding (jbh@site-ations.com) -->
<!-- Web Site: http://www.site-ations.com -->
<!-- Day images (c): http://www.site-ations.com -->
<!-- Month images (c): http://www.bruce-hamilton.com -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
theDate= new Date();
days = new Array();
days[1] ="1st.gif";
days[2] ="2nd.gif";
days[3] ="3rd.gif";
days[4] ="4th.gif";
days[5] ="5th.gif";
days[6] ="6th.gif";
days[7] ="7th.gif";
days[8] ="8th.gif";
days[9] ="9th.gif";
days[10] ="10th.gif";
days[11] ="11th.gif";
days[12] ="12th.gif";
days[13] ="13th.gif";
days[14] ="14th.gif";
days[15] ="15th.gif";
days[16] ="16th.gif";
days[17] ="17th.gif";
days[18] ="18th.gif";
days[19] ="18th.gif";
days[20] ="20th.gif";
days[21] ="21st.gif";
days[22] ="22nd.gif";
days[23] ="23rd.gif";
days[24] ="24th.gif";
days[25] ="25th.gif";
days[26] ="26th.gif";
days[27] ="27th.gif";
days[28] ="28th.gif";
days[29] ="29th.gif";
days[30] ="30th.gif";
days[31] ="31st.gif";
function printDate() {
document.write('<img src="' + days[theDate.getDate()] + '">'); // day
}
// End -->
</script>
khalidali63
05-13-2003, 08:51 AM
I see your problem....document.write actually moves all the code out of scope after its executed.
do the following.
1.Remove this line of code
document.write('<img src="' + days[theDate.getDate()] + '">'); // day
2.replace it with the following line of code
document.getElementById("div_img").innerHTML = ('<img src="' + days[theDate.getDate()] + '">'); // day
3. Now in the HTML add the following lineof code right were you want this image to appear.
<div id="div_img"></div>
jjski
05-13-2003, 09:04 AM
Thanks for the help, but I can't get that to work. Remember I am not a programmer, so here is the code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Jeff Harding (jbh@site-ations.com) -->
<!-- Web Site: http://www.site-ations.com -->
<!-- Day images (c): http://www.site-ations.com -->
<!-- Month images (c): http://www.bruce-hamilton.com -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
theDate= new Date();
days = new Array();
days[1] ="1st.gif";
days[2] ="2nd.gif";
days[3] ="3rd.gif";
days[4] ="4th.gif";
days[5] ="5th.gif";
days[6] ="6th.gif";
days[7] ="7th.gif";
days[8] ="8th.gif";
days[9] ="9th.gif";
days[10] ="10th.gif";
days[11] ="11th.gif";
days[12] ="12th.gif";
days[13] ="13th.gif";
days[14] ="14th.gif";
days[15] ="15th.gif";
days[16] ="16th.gif";
days[17] ="17th.gif";
days[18] ="18th.gif";
days[19] ="18th.gif";
days[20] ="20th.gif";
days[21] ="21st.gif";
days[22] ="22nd.gif";
days[23] ="23rd.gif";
days[24] ="24th.gif";
days[25] ="25th.gif";
days[26] ="26th.gif";
days[27] ="27th.gif";
days[28] ="28th.gif";
days[29] ="29th.gif";
days[30] ="30th.gif";
days[31] ="31st.gif";
function printDate() {
document.getElementById("div_img").innerHTML = ('<img src="' + days[theDate.getDate()] + '">'); // day
}
// End -->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="540" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="230" height="50"></td>
<td width="310"></td>
</tr>
<tr>
<td height="279"></td>
<td valign="top"><div id="div_img"></div></td>
</tr>
<tr>
<td height="176"></td>
<td></td>
</tr>
</table>
</body>
</html>
khalidali63
05-13-2003, 09:23 AM
oh okkay..you'd need more code then that to take care of your problem....let me see .....
khalidali63
05-13-2003, 09:46 AM
Follow th elink below..it shoudl do it...:-)
http://68.145.35.86/temp/DailyImageSwapper.html
jjski
05-13-2003, 09:58 AM
You are really close! There are two issues though. One is that it says that I need to install a language pack everytime it refreshes. Also windows gives a warning when I do change the calendar date to refresh it. Also if you change the calendar back a date, it will not refesh. (Not a big deal as I wouldn't be doing that. Any thoughts?
khalidali63
05-13-2003, 10:02 AM
Try it now....
jjski
05-13-2003, 10:03 AM
I solved the alert problem, but how do I get rid of the language pack thing?
khalidali63
05-13-2003, 10:15 AM
that has to do with your system....typically ithappens when you visit a site that uses custom language
characters,and once browser detects that it asks for a download....in the code I posted,I have taken out anything that could possibly cause that.....take a look
jjski
05-13-2003, 10:20 AM
That works perfectly! You solved a lot of problems around here. I really appreciate you putting that together for me.
khalidali63
05-13-2003, 10:31 AM
You are welcome...
:D