Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

expiring images

Status
Not open for further replies.

happyPanda

Technical User
Jul 21, 2008
2
I have a script that shows an image but the image goes away at a certain time. The problems I'm having are:
1. I want to make the images link to some site.
2. How do I use it for more than 1 image?

THis is the code:
Code:
<html>
<head>
<script type="text/javascript">

function disappearImg(){
var dispT;
var now = new Date();
var yr = now.getFullYear();
var mn = now.getMonth();
var dy = now.getDate()
var hr = now.getHours();

var expiresyr = 2008;
var expiresmn = 6;  // months 0 - 11
var expiresdy = 28;
var expireshr = 23;
var show = 0;

if (yr < expiresyr) {
show = 1;
}
if ((yr == expiresyr) && (mn < expiresmn)) {
show = 1;
}
if ((yr == expiresyr) && (mn == expiresmn) && (dy < expiresdy)) {
show = 1;
}
if ((yr == expiresyr) && (mn == expiresmn) && (dy == expiresdy) && (hr < expireshr)) {
show = 2;
}

if (show >= 1) {
dispT = "<img src='[URL unfurl="true"]http://codingforums.com/img/logo.gif'>";[/URL]
}
else {
dispT = "";
}

document.getElementById('imgDisplay').innerHTML = dispT;
if (show == 2) {
setTimeout("disappearImg",10000);  // check every 10 seconds on expiry day until expiry time reached
}
}

</script>

</head>

<body onLoad="disappearImg()">
<div id="imgDisplay"></div>

</body>
</html>
 
1: You can insert an anchor in the "dispT" string around the image.

2. That depends. First you need to work out how and when the second image will appear. Right now, we don't know.

P.S. A quick tip for a good life here on Tek-Tips... It's a forum where posters are encouraged to work on their own problems, and ask for help when they need help with a specific issue, rather than people coding entire solutions. I'm only mentioning it because I noticed you came here from CodingForums.com where people stopped helping you after you asked many questions without seeming to try things for yourself.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
This is what I have so far but it's still not working:
Code:
<script type="text/javascript">

function disappearImg(){
var dispT;
var now = new Date();
var yr = now.getFullYear();
var mn = now.getMonth();
var dy = now.getDate()
var hr = now.getHours();
var mns = now.getMinutes();

var expiresyr = 2008;
var expiresmn = 6;  // months 0 - 11
var expiresdy = 7;
var expireshr = 31;
var expiresmns = 2; //or whatever

var show = 0;

if (yr < expiresyr) {
show = 1;
}
if ((yr == expiresyr) && (mn < expiresmn)) {
show = 1;
}
if ((yr == expiresyr) && (mn == expiresmn) && (dy < expiresdy)) {
show = 1;
}
if ((yr == expiresyr) && (mn == expiresmn) && (dy == expiresdy) && (hr < expireshr)) {
show = 1;
}
if ((yr == expiresyr) && (mn == expiresmn) && (dy == expiresdy) && (hr == expireshr) && (mns < expiresmns)) {
show = 2;
}

if (show >= 1) {
dispT = "<a href='[URL unfurl="true"]http://www.google.com'><img[/URL] src='[URL unfurl="true"]http://img[/URL] url'></a>";
}
else {
dispT = "";
}

document.getElementById('imgDisplay').innerHTML = dispT;
if (show == 2) {
setTimeout("disappearImg",10000);  // check every 10 seconds on expiry day until expiry time reached
}
}

</script>
<script type="text/javascript">

function disappearImg2(){
var dispT2;
var now2 = new Date();
var yr2 = now.getFullYear();
var mn2 = now.getMonth();
var dy2 = now.getDate()
var hr2 = now.getHours();
var mns2 = now.getMinutes();

var expiresyr2 = 2008;
var expiresmn2 = 6;  // months 0 - 11
var expiresdy2 = 7;
var expireshr2 = 28;
var expiresmns2 = 41; //or whatever

var show2 = 0;

if (yr2 < expiresyr2) {
show2 = 1;
}
if ((yr2 == expiresyr2) && (mn2 < expiresmn2)) {
show2 = 1;
}
if ((yr2 == expiresyr2) && (mn2 == expiresmn2) && (dy2 < expiresdy2)) {
show2 = 1;
}
if ((yr2 == expiresyr2) && (mn2 == expiresmn2) && (dy2 == expiresdy2) && (hr2 < expireshr2)) {
show2 = 1;
}
if ((yr2 == expiresyr2) && (mn2 == expiresmn2) && (dy2 == expiresdy2) && (hr2 == expireshr2) && (mns2 < expiresmns2)) {
show2 = 2;
}

if (show2 >= 1) {
dispT2 = "<a href='[URL unfurl="true"]http://www.aol.com'><img[/URL] src='[URL unfurl="true"]http://url.gif'></a>";[/URL]
}
else {
dispT2 = "";
}

document.getElementById('imgDisplay2').innerHTML = dispT2;
if (show2 == 2) {
setTimeout("disappearImg2",10000);  // check every 10 seconds on expiry day until expiry time reached
}
}

</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top