Creating temporary links that expire?

L

Levi

I am developing a web site for a summer comedy series. The site has
links to buy tickets but I want them to disappear two hours before the
show begins. Does anyone know how to use a simple javascript that
shows and hides text and links after a date has passed?

lee317
 
L

Lee

Levi said:
I am developing a web site for a summer comedy series. The site has
links to buy tickets but I want them to disappear two hours before the
show begins. Does anyone know how to use a simple javascript that
shows and hides text and links after a date has passed?

This example only hides the "buy" link after the date has passed
(it actually checks to see if it's within 2 hours of the data/time).
It assumes that you and your customers are within the same time
zone and that there won't be a Daylight Saving Time change just
before showtime. Older browsers and browsers that have javascript
disabled will still see the link.


<html>
<head>
<script type="text/javascript">
var TWO_HOURS=7200000;
function checkExpiry(img,dateString){
var showTime=new Date(dateString);
var now=new Date();
if(img.parentNode && (showTime-now)<TWO_HOURS){
img.parentNode.style.visibility="hidden";
}
}
</script>
</head>
<body>
<table>
<tr>
<td>Show 1</td>
<td><a href="linkToBuyTickets.html"><img border="0"
src="http://www.azphx.com/dhtml/tmp/buy5025.gif"
onload="checkExpiry(this,'Mon, 25 Dec 1995 13:30')"></a>
</td>
</tr>
<tr>
<td>Show 2</td>
<td><a href="linkToBuyTickets.html"><img border="0"
src="http://www.azphx.com/dhtml/tmp/buy5025.gif"
onload="checkExpiry(this,'Mon, 25 Dec 2004 13:30')"></a>
</td>
</tr>
</table>
</body>
</html>
 
M

Matthias H. Risse

you could also do it in php.
check php.net for date-calculation functions
 
L

Levi

Thanks so much...this is perfect!

Lee said:
Levi said:

This example only hides the "buy" link after the date has passed
(it actually checks to see if it's within 2 hours of the data/time).
It assumes that you and your customers are within the same time
zone and that there won't be a Daylight Saving Time change just
before showtime. Older browsers and browsers that have javascript
disabled will still see the link.


<html>
<head>
<script type="text/javascript">
var TWO_HOURS=7200000;
function checkExpiry(img,dateString){
var showTime=new Date(dateString);
var now=new Date();
if(img.parentNode && (showTime-now)<TWO_HOURS){
img.parentNode.style.visibility="hidden";
}
}
</script>
</head>
<body>
<table>
<tr>
<td>Show 1</td>
<td><a href="linkToBuyTickets.html"><img border="0"
src="http://www.azphx.com/dhtml/tmp/buy5025.gif"
onload="checkExpiry(this,'Mon, 25 Dec 1995 13:30')"></a>
</td>
</tr>
<tr>
<td>Show 2</td>
<td><a href="linkToBuyTickets.html"><img border="0"
src="http://www.azphx.com/dhtml/tmp/buy5025.gif"
onload="checkExpiry(this,'Mon, 25 Dec 2004 13:30')"></a>
</td>
</tr>
</table>
</body>
</html>
 

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

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top