473,386 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Date Expiry of Page using Javascript ?

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?

Jul 29 '05 #1
4 2812
alu

<ia***@aol.com> wrote in message
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/calen...to-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
Jul 29 '05 #2
JRS: In article <%u*******************@news20.bellglobal.com>, dated
Fri, 29 Jul 2005 10:58:38, seen in news:comp.lang.javascript, alu
<no**@none.com> posted :
<ia***@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/calen...to-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) .

--
© 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.
Jul 29 '05 #3
alu

"Dr John Stockton" <jr*@merlyn.demon.co.uk> wrote
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

Jul 30 '05 #4
JRS: In article <vL*******************@news20.bellglobal.com>, dated
Fri, 29 Jul 2005 22:38:53, seen in news:comp.lang.javascript, alu
<no**@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.

--
© 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.
Jul 30 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Vince C. | last post by:
Hi all. I'm trying to set a cookie expiry date but my script is JS (JavaScript). I've tried Response.Cookies("Test").Expires = Date(); Response.Cookies("Test").Expires =...
7
by: What-a-Tool | last post by:
How does the expire date work setting it server side with asp. I know with javascript setting it client side it will be set to the clients local time, and therefore expire when the clients local...
2
by: gardnern | last post by:
Is it possible to get the expiration date/time of a cookie? I need to limit someone to visiting a couple of pages for 45 minutes max and would like to show them how much time they have left. I dont...
4
by: William Bradley | last post by:
I have two cells on a form. One of them is the "Production Date" and the other is the "Expiry Date". The "Expiry Date" is 183 days after the "Production Date." On an Excel spreadsheet, the...
2
by: William Bradley | last post by:
"Marshall Barton" <marshbarton@wowway.com> wrote in message news:9as9lvgpnp783kogctb88c8giaepb5uf6g@4ax.com... > William Bradley wrote: > >I have two cells on a form. One of them is the...
3
by: hasanainf | last post by:
Hi all, What will be the best database design for an inventory control that uses expiry date for its products. Over a period of time, a particular product will have many expiry date and that...
32
by: paul | last post by:
HI! I keep on getting this error and I have tried different things but I am not sure how to send the expiring date. The error that I am getting in Firefox 1.5 is "Error: expires.toGMTString is...
0
by: mplpost | last post by:
We have created a Certificate for the purpose of symmetric encryption. We did not mention the expiry date explicitly, only later we found out that, if expiry date not mentioned then the default...
4
peeaurjee
by: peeaurjee | last post by:
Hello, I have a query containing Serial, Name, Residence Visa Expiry Date in MS Access 2003. I need to put Residence Visa Registration Date in other field and that would be in reverse I mean 3...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.