Log in

View Full Version : Timer for image display.



rydorien
10-24-2011, 08:15 AM
Hello,

Does anyone have a script that removes a picture after a certain time? I guess this would be considered a timer action script.

Thanks

djr33
10-24-2011, 11:29 AM
"remove" is not very clear in this case. I don't know of any scripts in particular that exist for this, but it would certainly be possible to make one, depending on what you mean specifically.

Do you want to use Javascript? You just want to hide an image if it is past a certain time? You could look into scripts that display images at certain times and modify them to instead hide images (for example, element.style.display = 'none';).
If you do use this method, though, it will be possible to find the image in the source code. Javascript can't do anything about that because it only changes what has already loaded.

If you want to completely "remove" an image from your page so that no one can find it at all, you will need to use a serverside language like PHP-- but instead of "removing" it you just won't generate it in the first place.

vwphillips
10-24-2011, 12:30 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
</head>

<body>
<img id="tst1" src="http://www.vicsjavascripts.org.uk/StdImages/Egypt5.jpg" />
<img id="tst2" src="http://www.vicsjavascripts.org.uk/StdImages/Egypt6.jpg" />

<script type="text/javascript">
/*<![CDATA[*/

function Remove(id,ms){
var obj=document.getElementById(id);
if (obj&&typeof(ms)=='number'){
setTimeout(function(){ obj.parentNode.removeChild(obj); },ms);
}
}

Remove('tst1',4000)
Remove('tst2',3000)
/*]]>*/
</script>
</body>

</html>

djr33
10-24-2011, 12:42 PM
That script uses a delay (for example, 10 seconds) to remove an image. My suggestions were about absolute time (time of day, or date).

Rydorien, which of these did you want?