Date Expiry of Page using Javascript ?

I

ianv2

Hi

Is the following possible using Javascript ?

I would like a page to redirect to another page if the page expiry has
passed.

E.G.

If my questionnaireform.html page had an expiry date of July 31, if I
tried to access that page after this date (i.e. August 1st) I would be
redirected to index.html.

Is this possible?
 
A

alu

Hi

Is the following possible using Javascript ?

I would like a page to redirect to another page if the page expiry has
passed.

E.G.

If my questionnaireform.html page had an expiry date of July 31, if I
tried to access that page after this date (i.e. August 1st) I would be
redirected to index.html.

Is this possible?

________________________________

quickly modified from Don Demrow's script at
http://javascript.internet.com/calendars/auto-expire.html


<body>

<script type="text/javascript">

// Set the expiry date below
var expireDate = "20050731";

var expireYear = expireDate.substring(0,4)
var expireMonth = expireDate.slice(4,-2)
var expireDay = expireDate.slice(6)
var nowDate = new Date();
var day = nowDate.getUTCDate();
var month = nowDate.getUTCMonth();
var month1 = month + 1;
if (month1 < 10)
{
month1 = "0" + month1;
}
if (day < 10)
{
day = "0" + day;
}
var year = nowDate.getUTCFullYear();
var GMTdate = year + "" + month1 + "" + day

if (GMTdate > expireDate) {location.href = "index.html"}

</script>

still questionnaireform.html

</body>

________________________________

-alu
 
D

Dr John Stockton

JRS: In article <%[email protected]>, dated
Fri, 29 Jul 2005 10:58:38, seen in alu
quickly modified from Don Demrow's script at
http://javascript.internet.com/calendars/auto-expire.html

// Set the expiry date below
var expireDate = "20050731";

var expireYear = expireDate.substring(0,4)
var expireMonth = expireDate.slice(4,-2)
var expireDay = expireDate.slice(6)
var nowDate = new Date();
var day = nowDate.getUTCDate();
var month = nowDate.getUTCMonth();
var month1 = month + 1;
if (month1 < 10)
{
month1 = "0" + month1;
}
if (day < 10)
{
day = "0" + day;
}
var year = nowDate.getUTCFullYear();
var GMTdate = year + "" + month1 + "" + day

if (GMTdate > expireDate) {location.href = "index.html"}



Bloatware. All that is needed is

if (new Date() > new Date("2005/07/31")) location.href = "index.html"

If the expiry date is computed, just set it in a Date Object and put
that after the comparison operator.

If the expiry date is to be UTC, add " UTC" to the string, or use
new Date(2005, 7-1, 31) .

Here the expiry date should be the first non-allowed date; one could use
new Date(2005, 7-1, 31+1) .
 
A

alu

Dr John Stockton said:
Bloatware. All that is needed is

if (new Date() > new Date("2005/07/31")) location.href = "index.html"

If the expiry date is computed, just set it in a Date Object and put
that after the comparison operator.

If the expiry date is to be UTC, add " UTC" to the string, or use
new Date(2005, 7-1, 31) .

Here the expiry date should be the first non-allowed date; one could use
new Date(2005, 7-1, 31+1) .


Thanks John, 'knew it was fat....was even fatter before.
Question - while I was checking the original code in Firefox,

var nowDate = new Date();
var year = nowDate.getYear();

year returned '105', while in IE, year returned '2005'.
Can you explain?

Changing the line to: var year = nowDate.getUTCFullYear()
cleared up the discrepancy.
-alu
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated
Fri, 29 Jul 2005 22:38:53, seen in alu
var nowDate = new Date();
var year = nowDate.getYear();

year returned '105', while in IE, year returned '2005'.
Can you explain?

Mere idiocy on the part of early implementers of javascript, back in the
1900's and not expecting the 2000's.

Since they were accustomed to writing the year with two digits (which is
moderately unambiguous between the 31st year of a century and the last),
they provided a primitive for a two-digit year number and none for a
proper year number. Naturally, they implemented different behaviours
for after the year '99. Some made the next year 0, some 100, some 2000.
My Web page js-date0.htm refers.

Perfectly stupid : it would have been much simpler to give the full year
in the first place, and it can so readily be converted to two digits if
desired either by using %100 or by substringing. I have a routine, BTW,
for determining the full year in browsers that lack the full year
functions - getFY(), in my js-date0.htm.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top