...

View Full Version : 'redirect user between this date and this date' code ...



davidfarndon
03-22-2005, 07:46 PM
Does anyone have a nifty bit of code I could 'borrow' please?

I need to have an index page which redirects to THISindex.htm between specified dates (i.e. from 24 March 2005 until 29 March 2005) and on any other date THATindex.htm is displayed instead

... It doesn't need to be so accurate as to change at a certain time (though it would be handy to know this for the future)

I have tried a couple of routes, but they just don't seem to work .. in fact, so far nothing happens at all, I just get the index page (with the code sitting doing nothing).

Help?

David

Willy Duitt
03-22-2005, 09:37 PM
<script type="text/javascript">
<!--//
function checkDate(startDate,endDate,URL){
if(new Date() >= new Date(startDate) && new Date() <= new Date(endDate))
location.href = URL;
} checkDate('03/21/2005','03/29/2005','THISindex.html');
//-->
</script>


If you want to redirect by a certain time you will need to jump thru a few more hoops...
Try searching and reading up on: javascript date object....

.....Willy

Edit: Oooops... I did not notice your else THATindex.html...



<script type="text/javascript">
<!--//
function checkDate(startDate,endDate,URL){
if(new Date() >= new Date(startDate) && new Date() <= new Date(endDate)){
location.href = URL;
} else{ location.href = 'THATindex.html' };
} checkDate('03/21/2005','03/29/2005','THISindex.html');
//-->
</script>

davidfarndon
03-22-2005, 09:45 PM
FANTASTIC ...

I owe you a pint.

I shall insert and play .. but it looks like it will be just the job .. thanks Willie, you are a star!

David

davidfarndon
03-22-2005, 11:40 PM
just to say that I installed this into an index page all of its own, and it worked like magic. I changed my system date and it sent me to the right page .. again .. spot on.

so a BIG thank you.

David



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum