PDA

View Full Version : Date-specific web page actions


Pete33
10-15-2007, 09:42 AM
Hi guys. I have no idea which category to post this in, or if it's even possible to achieve, so think of it as a challenge to your web skills :)

In Visual Basic you can build a routine that checks a value (such as today's date). If today's date matches the date stored then an action will occur.

My question is, can this be done with a web page?

I'd like an index page to be active until a certain date, and after that date I would like it to automatically redirect to a different page which carries a message for the user. The page should operate completely normally until the date I set is reached, with no sign that anything is going to happen. Once the date is reached, anyone calling the index page will be instantly redirected to my message page instead.

What do you think? Is it a possibility?

diades
10-16-2007, 07:51 AM
Hi Peter

I think that you have two choices here, the first is client-sdie scripting that when loading, checks the current date and, if required, re-directs. It will work but, search engines will not like it so much and if the user disallows scripting then it will not happpen. The second would be to check server-side when the request for the page is made and react accordingly. This would, of course, require server-side scripting rights.

Pete33
10-16-2007, 09:16 AM
Hi Keith

The search engines aren't really a concern at the moment. This would be a temporary measure for a brand new web site. Scripting should work okay, too, so how do you think it should be achieved?

diades
10-16-2007, 10:25 AM
Hi

Something like this:

<script type="text/javascript">
//<![CDATA[
cutOffDate = "10-16-2007"; //m-d-y
targetDt = new Date(cutOffDate); //create the target date
dtNow = new Date(); //get the ciurrent date
//compare the current date with the target date
if(dtNow.getDate() == targetDt.getDate() &&
dtNow.getMonth() == targetDt.getMonth() &&
dtNow.getYear() == targetDt.getYear())
{
//they match so go to the new page
location = "index2.htm"
}
//]]>
</script>

Pete33
10-17-2007, 09:55 AM
Hmm... It looks very promising but on my test page it doesn't actually work. The page just sits there, not redirecting.

I tried it with today's date, and with yesterday's date, and no reaction. I've tried it with the script in the body, and then in the header, too.

Have I done something wrong with it?