[Javascript] writing/reading the same file at the same time

Günther Mittermayer g_mitter at web.de
Tue May 25 08:12:43 CDT 2004


Hi there, 

I have an application, where the JavaScript refreshes an Image contained in a HTML page.

Since this image is continuously generated by a Perl script, I get a random blinking of the image, that I am assuming to be due to the times when both (the Javascript and the Perl script) try to access the image at the same time.

anyone got an Idea on how to solve that?  I tried "preloading" the image, but nope.. doesn't work.

It is not very critical if I miss some refreshes, that is, if the Javascript tries reading the file when it is in use, it is ok not to do anything, and wait for the next loop....  
does JavaScript handle exceptions?? how does that work, with try/catches just like in Java?

any help/ comments are welcome,
Günther.

here is some code:

<html>
<head>

<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="description" content="Fireworks Splice HTML">

<script type="text/javascript">
function refresh_image()
{

<!-- Preloads the Image to a temporary variable to avoid blinking - Nice try.. but not working-->
img_tmp = new Image();
img_tmp.src = "theimage.png";

<!-- Refreshes the image -->
var img = document.getElementById('imageID');
img.src = img_tmp.src;
setTimeout('refresh_image()',600)
};

</script>
</head>
<body onLoad="setTimeout('refresh_image()',600)">
<form method='POST' action='/cgi-bin/elem_props.cgi' target='elem_props'>
	<center><input type='image' name='image1' id='imageID' src='theimage.png'></center>
</form>
</body>
</html>

_______________________________________________________________________
Moechten Sie Ihre SMS noch ausdrucksstaerker und emotionaler gestalten?
Fuegen Sie einfach ein Bild hinzu! http://freemail.web.de/?mc=021194




More information about the Javascript mailing list