...

View Full Version : Help Needed - Jscript Redirect



Mria
07-10-2003, 02:02 PM
I have a simple request.. I hope. I am using a redirect that is a simple schedule redirect. It works fine, and I want to alter it slightly to add a start time and an end time. It schedules the page for a particular date of the week. I need to have this page replaced at 12 noon on 7/17/03, and I need it to be back up in the am of 7/21.

How do I incorporate the time into this script?

<script language="JavaScript" type="text/JavaScript">
<!--
function pagetime(yy, mm, dd, length, url, target) {
mm = parseInt(mm, 10);
dd = parseInt(dd, 10);
mm -= 1;
var day = 86400000;
var week = day * 7;
var today = (new Date()).getTime();
var start = (new Date(yy, mm, dd)).getTime();
var future = new Date(start + (day * length));
if (today >= start && today <= future) {
if (target) {
eval("parent." + target + ".location.replace(url)");
} else {
eval("parent.location.replace(url)");
}
}
document.MM_returnValue = false;
}
//-->
</script>

<body onLoad="pagetime('2003','07','14','3','Templink.htm','');return document.MM_returnValue">
</body>

Any assistance is appreciated.

Thank you,

Mr J
07-10-2003, 05:01 PM
Please try the following script.

The date and time are altered in the Target_Date array

The url's are placed in the Set_Url array




<HTML>
<HEAD>
<TITLE>Document Title</TITLE>

<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 be between 0 and 11.
// 00 = January, 01 = February, 02 = March etc.
Target_Date=new Array()
Target_Date[Target_Date.length] = new Date(2003,06,17,12,00,01) // target date 1
Target_Date[Target_Date.length] = new Date(2003,06,21,00,00,01) // target date 2

// enter URL to correspond with appropriate Target_Date[index]
Set_Url=new Array()
Set_Url[Set_Url.length]="templink.htm"
Set_Url[Set_Url.length]="oldpage.htm"

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)

loc=Set_Url[Count]
location=loc

}
// include onload="Countdown()" in the opening BODY tag
// -->
</script>
</HEAD>
<BODY onload="Countdown()">

</BODY>
</HTML>

Mria
07-10-2003, 05:20 PM
Thank you, I'll try that today.

:)

PS: This is a great board, and it's nice to have this kind of resource to turn to.

Mria
07-10-2003, 06:57 PM
My body tag currently has a whole preload script in it. Should I place the onload="Countdown()" section before or after the preloaded images (or does this not make a difference?)

Thank you. (Still testing the script).

:D

Mr J
07-10-2003, 07:16 PM
If you already have an onload event in the opening BODY tag then you need to to put in a semicolon between that one and Countdown()


<BODY onload="preload() ; Countdown()">

Mria
07-11-2003, 01:52 PM
Hi, this didn't work. I'm using Macromedia Dreamweaver MX to do the coding. Is there no way to incorporate it into my original script?

No redirection is occurring at all on my test page. (I changed the dates and times for my test. I also made sure that I changed the amount of days for the test.)

Any other ideas?

Thank you.

Mr J
07-11-2003, 03:53 PM
I have not used Macromedia Dreamweaver MX so I cannot remark on how it incorporates javascript into pages.

I have posted a zip file containing the page I used to test the script.

Experiment with this page on its own.

When you enter the date and time make sure you enter it as




Target_Date[Target_Date.length] = new Date(year, month,date,hour, minites,seconds)


Target_Date[Target_Date.length] = new Date(2003,06,11,15,39,01) // target date 1




Note that the month entry is one less than the actual month number.

This month (July) = 07 therefore for the script entry July = 06

I tested the script by putting todays date, the current hour and altering just the minite entries.


The script redirected to the sites I entered in the "Set_Url" array at the times I entered.

I did notice in the script I posted above I forgot to take out my test alert but the script should still have redirected.

See how you go with my test page

Mr J
07-11-2003, 03:53 PM
Oops forgot the zip

:o

Mria
07-14-2003, 12:38 PM
Ok, I will give it a shot. ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum