Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / July 2005



Tip: Looking for answers? Try searching our database.

Date Expiry of Page using Javascript ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ianv2@aol.com - 29 Jul 2005 10:05 GMT
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?
alu - 29 Jul 2005 15:58 GMT
<ianv2@aol.com> wrote in message
> Hi
>
[quoted text clipped - 10 lines]
>
> 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
Dr John Stockton - 29 Jul 2005 22:47 GMT
JRS:  In article <%urGe.6039$d02.844466@news20.bellglobal.com>, dated
Fri, 29 Jul 2005 10:58:38, seen in news:comp.lang.javascript, alu
<none@none.com> posted :
><ianv2@aol.com> wrote in message

>> 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

>// Set the expiry date below
>var expireDate = "20050731";
[quoted text clipped - 18 lines]
>
>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) .

Signature

© John Stockton, Surrey, UK.  ?@merlyn.demon.co.uk   Turnpike v4.00   IE 4 ©
<URL:http://www.jibbering.com/faq/>  JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

alu - 30 Jul 2005 03:38 GMT
> Bloatware.  All that is needed is
>
[quoted text clipped - 8 lines]
> 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
Dr John Stockton - 30 Jul 2005 22:29 GMT
JRS:  In article <vLBGe.6277$d02.925568@news20.bellglobal.com>, dated
Fri, 29 Jul 2005 22:38:53, seen in news:comp.lang.javascript, alu
<none@none.com> posted :

>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.

Signature

© John Stockton, Surrey, UK.  ?@merlyn.demon.co.uk   Turnpike v4.00   IE 4 ©
<URL:http://www.jibbering.com/faq/>  JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.