Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Expire page

  1. #1
    New Coder
    Join Date
    Jul 2003
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Expire page

    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.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Have a look at this sample script:

    Code:
    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) {
    	location.replace(redirectURL); 
    }
    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.
    De gustibus non est disputandum.

  • #3
    New Coder
    Join Date
    Jul 2003
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I'll try it

    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •