This script was designed to load URLs on a given day at a given time, other uses could be to show an image, play a sound, change background colour, etc. etc.
The script checks the Current Date against a Target Date, when the Target Date is reached the URL for that date is loaded.
The Target Dates are held in an array which allows the setting of multiple dates, or multiple times on the same date.
When a Target Date is reached the URL for that date is shown until the next Target Date.
You can also set the number of days that the last URL is shown. Once this period has been reached an alert is given as a reminder that new target dates need to be set.
Any number of future Date and/or Times can be set. The blue text is where you enter the date and time.
The red is where you place your URL.
Target Dates must be in sequencial order within the array.
Add or delete entries as required.
If adding more entries to the tDate and tUrl arrays the index's must be consecutive.
I.E. tDate[4]=new Date(d,a,te, t,i,me)
<script type="text/javascript">
<!--
// Realise by jeff
// www.huntingground.freeserve.co.uk
// any modifications would be gratefully received
Display_period=5 // number of days to show last URL
// Enter new date using the format year,month,day,hours,minutes,seconds
// The month value must be between 0 and 11.
// 00 = January, 01 = February, etc.
tDate=new Array()
tDate[0] = new Date(2002,10,28,00,00,01) // target date 1
tDate[1] = new Date(2002,10,28,00,00,01) // target date 2
tDate[2] = new Date(2002,10,28,00,00,01) // target date 3
tDate[3] = new Date(2002,10,28,00,00,01) // target date 4
// enter URL to correspond with appropriate tDate[index]
tUrl=new Array()
tUrl[0]="http://www.microsoft.com" // url 1
tUrl[1]="http://www.huntingground.freeserve.co.uk" // url 2
tUrl[2]="http://www.dhtmlnirvana.com" // url 3
tUrl[3]="http://www.webdeveloper.earthweb.com" // url 4
today=new Date() // get current date
function countdown(){
for(i=0;i<tDate.length;i++){ // look through tDate array, convert dates to milliseconds using .getTime()
if(today.getTime()>tDate[i].getTime()){ // if current date greater than tDate[i]
count=i // array index
}
}
if(count>tDate.length-1){ // if count exceeds tDate length
count=tDate.length // keep count at tDate length
}
Where_To()
}
function Where_To(){
Last_Entry_Date =tDate[tDate.length-1]
Days_Expired=Math.floor((today-Last_Entry_Date)/86400000)
if(count==tDate.length-1&&Days_Expired>Display_period-1){
alert("NEW TARGET DATE ENTRIES REQUIRED\n\n"
+Days_Expired+" days have lapsed since the last Target Date entry of:\n\n"
+ Last_Entry_Date+"\n\nThe limit is currently set at "+Display_period+" days")
}
else{
loc=tUrl[count]
newwin=window.open(loc,'win1','width=600,height=250,top=10,left=100,location=yes')
}
}
// include onload="countdown()" in the opening BODY tag
// -->
</script>
The following script loads Urls weekly.
52 entries are required in the tUrl array.
<script type="text/javascript">
<!--
// Load weekly script realised by apacheJeff
// www.huntingground.freeserve.co.uk
// The getWeek function formulated by http://developer.irt.org/script/914.htm
tUrl=new Array()
tUrl[0]="http://www.webreference.com" // week 1
tUrl[1]="http://developer.irt.org" // week 2
tUrl[2]="http://www.dhtmlnirvana.com" // week 3
tUrl[3]="http://www.webdeveloper.earthweb.com" // week 4
tUrl[4]="http://www.pcplus.co.uk" // week 5
tUrl[5]="http://www.netmag.co.uk" // week 6
tUrl[6]="http://javascriptsource.com" // week 7
tUrl[7]="http://www.codebrain.com" // week 8
tUrl[8]="http://www.dansteinman.com" // week 9
tUrl[9]="http://www.hrgiger.com" // week 10
function getWeek(year,month,day) {
var Now = new Date(year,month,day);
var newYear = new Date(year,0,1);
var modDay = newYear.getDay();
// Start week on a monday
if(modDay == 0){
modDay=6
}
else{
modDay--
}
var daynum = ((Date.UTC(year,Now.getMonth(),Now.getDate(),0,0,0) - Date.UTC(year,0,1,0,0,0)) /1000/60/60/24) + 1;
if (modDay < 4 ){
var weeknum = Math.floor((daynum+modDay-1)/7)+1
}
else{
var weeknum = Math.floor((daynum+modDay-1)/7);
}
if (weeknum == 0) {
year--;
var prevNewYear = new Date(year,0,1);
var prevmodDay = prevNewYear.getDay();
if(prevmodDay == 0){
prevmodDay = 6
}
else{
prevmodDay--
}
if(prevmodDay < 4){
weeknum = 53
}
else{
weeknum = 52
}
}
location=tUrl[weeknum-1]
return + weeknum;
}
var toDay = new Date();
getWeek(toDay.getYear(),toDay.getMonth(),toDay.getDate())
//-->
</script>
The following script loads monthly.
12 entries are required in the tUrl array.
<script type="text/javascript"> <!-- // Realise by jeff // www.huntingground.freeserve.co.uk // The month value is an integer between 0 and 11 (Jan to Dec). tUrl=new Array() tUrl[0]="http://www.webreference.com" // jan tUrl[1]="http://nonags.com" // feb tUrl[2]="http://www.dhtmlnirvana.com" // mar tUrl[3]="http://www.webdeveloper.earthweb.com" // apr tUrl[4]="http://www.pcplus.co.uk" // may tUrl[5]="http://www.netmag.co.uk" // jun tUrl[6]="http://javascriptsource.com" // jul tUrl[7]="http://www.codebrain.com" // aug tUrl[8]="http://www.dansteinman.com" // sept tUrl[9]="http://www.hrgiger.com" // oct tUrl[10]="http://www.joecartoon.com" // nov tUrl[11]="http://www.bravenet.com" // dec today=new Date() // get current date location=tUrl[today.getMonth()] // --> </script>