View Full Version : Expire page

07-15-2003, 07:38 AM
Hello there. I hope someone can help me. For the last week and a half I have been trying to write a script that will redirect my visitors after a certain date.

For example.

On my front page, I want to be able set a date so that my visitors will be redirected to a new page after October 2nd 2003.

Up untill the date, the front page should load.

After the date, the front page will not load and the visitors will be automatically redirected to a new page.

This will be used for some pages that I have created and have forgetten about.

Any help with this please let me know... I have been unsuccessful so far.

07-15-2003, 11:08 AM
Have a look at this sample script:

var expireDay = 2;
var expireMonth = 10;
var expireYear = 2003;
var redirectURL = 'http://www.example.com';

var now = new Date();
var expire = new Date(expireYear, expireMonth - 1, expireDay);

if (now > expire) {

The first four variables should be filled with the values you need. After that, a Date object with the current date is created, and also a Date object with the given expire date. The only gotcha here is that JavaScript month numbers start with 0 instead of 1, but the script takes care of that by subtracting 1 from the month variable.
And the if construct just checks if the current date is greater than the expiration date and if so, replaces the current location with the URL of the site you specified.

P.S: It is good style if you post the code you managed to come up with no matter how bad or disfunctional it actually is. People can then see where your main errors are and correct them. In the end, you probably learn even more from that. ;)

07-16-2003, 06:21 AM
This is what I had got so far....

var x =1
var y =6
var z =2003;
var newDate = new Date(z, y, x);
var oldDate = new Date();
if (oldDate >= newDate)
location.href = "new.htm";

Thanks mordred, I will try yours out.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum