PDA

View Full Version : Every month an other page


siflaar
12-25-2002, 07:26 AM
Hello All,

All the best for Xmas and 2003.

On my new website I have a page with a top and a bottom frame.
The page that is loaded in the bottom frame is differend for every month.
Is it possible to create a little script that is loading the correct page in the bottom frame according to the current month?
And is that month taken from the server side or the client side?

chrismiceli
12-25-2002, 12:53 PM
if it was done in javascript it would be taken from the client unfortunately, i am new to dates, but try this

test = new Date()
test0 = test.GetMonth();
switch (test0) {
case 0:
parent.framename.location.href = "january.html"
break
case 1:
//etc

siflaar
12-26-2002, 01:26 PM
Thanks for the direction Chris,

But where must I put the code? (I use javascript, but don't understand it completely)
Should it be on the page where the frames are defined, or where?

Mr J
01-02-2003, 08:03 PM
Put this script in a page and have the page initially load into your bottom frame.

The script is set to load a new page on the first of every month.
You can change the dates as required just follow the format.

Change the urls to the pages you want loading



<script language="Javascript">
<!--
// Realise by jeff
// www.huntingground.freeserve.co.uk
// any modifications would be gratefully received
Count= -1
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 an integer between 0 and 11 (representing the months January through December).
// 00 = January, 01 = February, etc.
Target_Date=new Array()
Target_Date[Target_Date.length] = new Date(2003,00,01,16,00,00)
Target_Date[Target_Date.length] = new Date(2003,01,01,16,00,00)
Target_Date[Target_Date.length] = new Date(2003,02,01,16,00,00)
Target_Date[Target_Date.length] = new Date(2003,03,01,16,00,00)
Target_Date[Target_Date.length] = new Date(2003,04,01,16,00,00)
Target_Date[Target_Date.length] = new Date(2003,05,01,16,00,00)
Target_Date[Target_Date.length] = new Date(2003,06,01,16,00,00)
Target_Date[Target_Date.length] = new Date(2003,07,01,16,00,00)
Target_Date[Target_Date.length] = new Date(2003,08,01,16,00,00)
Target_Date[Target_Date.length] = new Date(2003,09,01,16,00,00)
Target_Date[Target_Date.length] = new Date(2003,10,01,16,00,00)
Target_Date[Target_Date.length] = new Date(2003,11,01,16,00,00)

// enter URL to correspond with appropriate Target_Date[index]
Set_Url=new Array()
Set_Url[0]="http://www.webreference.com"
Set_Url[1]="http://nonags.com"
Set_Url[2]="http://www.dhtmlnirvana.com"
Set_Url[3]="http://www.webdeveloper.earthweb.com"
Set_Url[4]="http://www.pcplus.co.uk"
Set_Url[5]="http://www.netmag.co.uk"
Set_Url[6]="http://javascriptsource.com"
Set_Url[7]="http://www.codebrain.com"
Set_Url[8]="http://www.dansteinman.com"
Set_Url[9]="http://www.hrgiger.com"
Set_Url[10]="http://www.joecartoon.com"
Set_Url[11]="http://www.bravenet.com"
today=new Date() // get current date

function Countdown(){
for(i=0;i<Target_Date.length;i++){ // look through Target_Date array
if(today>Target_Date[i]){ // if current date greater than Target_Date[i]
Count++ // increment count by one
}
}
if(Count>Target_Date.length-1){ // if count exceeds Target_Date length
Count=Target_Date.length // keep count at Target_Date length
}
Where_To()
}

function Where_To(){
if(Count== -1){
return
}

Last_Entry_Date =Target_Date[Target_Date.length-1]
Days_Expired=Math.floor((today-Last_Entry_Date)/86400000)

if(Count==Target_Date.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=Set_Url[Count]
location=loc
}

}

setTimeout(" Countdown()",1000)
// -->
</script>

siflaar
01-03-2003, 06:31 AM
Hello Jeff,

Thanks for the reply.
Is it possible to change the code so it will only check the month and not the year also, ohterwise I have to change the code every year.
I use this code on a site for an astronomical observatory and it must show the skymap and interresting obects for the currnet month

Thanks for your reaction.

Mr J
01-03-2003, 06:46 PM
I think this should do what you require.


<script language="Javascript">
<!--
// Realise by jeff
// www.huntingground.freeserve.co.uk
// The month value is an integer between 0 and 11 (Jan to Dec).

Set_Url=new Array()
Set_Url[0]="http://www.webreference.com"
Set_Url[1]="http://nonags.com"
Set_Url[2]="http://www.dhtmlnirvana.com"
Set_Url[3]="http://www.webdeveloper.earthweb.com"
Set_Url[4]="http://www.pcplus.co.uk"
Set_Url[5]="http://www.netmag.co.uk"
Set_Url[6]="http://javascriptsource.com"
Set_Url[7]="http://www.codebrain.com"
Set_Url[8]="http://www.dansteinman.com"
Set_Url[9]="http://www.hrgiger.com"
Set_Url[10]="http://www.joecartoon.com"
Set_Url[11]="http://www.bravenet.com"

today=new Date() // get current date
Month=today.getMonth() // get current month

function Countdown(){
location=Set_Url[Month]
}
setTimeout(" Countdown()",1000)
// -->
</script>

Incarcerated15
01-04-2003, 01:40 AM
you could have it run a program on the server that does a repeated process and acts as a clock and have it change the page everytime it gets to the right time

chrismiceli
01-04-2003, 03:11 AM
what is wrong with my code?

Incarcerated15
01-04-2003, 03:17 AM
he doesn't know where to put it

Mr J
01-04-2003, 11:48 AM
chrismiceli

There is nothing wrong with your code as such, but if siflaar is new to javascript he might not know how to make up the rest of the code

siflaar
01-04-2003, 12:02 PM
Hello All,

Thanks for careing. I'm new to javascript but I think I should replace some lines from the first code with those of the second.
I will give is a try tommorow and let you know if I got it to work

Thanks again.

siflaar
01-05-2003, 12:22 PM
Hallo All,

Thanks for thinking for me... I used the last script and it works like... well like all that works well

Maybe if you have some time left, could you explane why you need the countdown function, is it not possible to activate the correct page in the timeout command itself?
And where does this 1000 stand for?

Mr J
01-05-2003, 03:04 PM
The function is not really necessary, a bad habit I have got into.

The 1000 sets the delay for when the function is called after the script loads.

1000 = milliseconds = 1 second

The following works just as well.

<script language="Javascript">
<!--
// Realise by jeff
// www.huntingground.freeserve.co.uk
// The month value is an integer between 0 and 11 (Jan to Dec).

Set_Url=new Array()
Set_Url[0]="http://www.webreference.com"
Set_Url[1]="http://nonags.com"
Set_Url[2]="http://www.dhtmlnirvana.com"
Set_Url[3]="http://www.webdeveloper.earthweb.com"
Set_Url[4]="http://www.pcplus.co.uk"
Set_Url[5]="http://www.netmag.co.uk"
Set_Url[6]="http://javascriptsource.com"
Set_Url[7]="http://www.codebrain.com"
Set_Url[8]="http://www.dansteinman.com"
Set_Url[9]="http://www.hrgiger.com"
Set_Url[10]="http://www.joecartoon.com"
Set_Url[11]="http://www.bravenet.com"

today=new Date() // get current date
Month=today.getMonth() // get current month
location=Set_Url[11]

// -->
</script>

siflaar
01-05-2003, 05:17 PM
You problably ment

location=Set_Url[month]

Thanks agian.
:thumbsup:

chrismiceli
01-05-2003, 10:03 PM
he probably ment parent.location.href=Set_Url[month];

Mr J
01-05-2003, 10:09 PM
Sorry didn't realise I'd left it in test mode :o


Please note the capital M


location=Set_Url[Month]