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

Hakan Magnusson hakan at backbase.com
Tue May 25 11:07:02 CDT 2004


Simply setting the src of a Image()-object does not halt the execution 
and wait for the image to be loaded. I suggest you set an event handler 
or onreadystate-handler on your image, and then do the swapping when 
you're sure the image is fully downloaded.

If I recall correctly, oImage.onload works in Mozilla, and 
oImage.onreadystatechange works in Internet Explorer. oImage.readyState 
should be '4' when it's done loading in Explorer.

Could we see your webcam when you're done? ;)

Regards,
H

Günther Mittermayer wrote:
> 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
> 
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
> 
> 



More information about the Javascript mailing list