Link to home
Start Free TrialLog in
Avatar of TheJoeShmoe
TheJoeShmoe

asked on

How to Automatically reload an image, after it has completed loading... NEED JS HELP!

Hello,

On my website I am trying to continuously refresh an image after it has been loaded but have found this to be quite tricky.  Although it is simple to use JavaScript to refresh the image every 5 seconds, on slow/mobile connections this does not work because it may take more than 5 seconds to load the image, at which point it would start over and try to load it again  thus never completing the update (*Note, It needs to update as fast as possible, so I cannot just increase it to 30 seconds).
So what I really need is some type of notification that the image is done downloading, and then update to the next image.

I imagine this should work like this:
1.      Start Image Load
2.      Wait 500ms, check to see if image has completed loading
                   If it has finished loading, loop back to number 1.
                   If it has not finished loading, loop back to number 2.

I am just not clear on a way to do this in Javascript.  Any ideas on how to make this happen?  Also to note, the main use of this is from the Safari browser, and also I cannot refresh the whole page, I can only refresh the image on the page.

Thanks in advance for any ideas you have on this!
ASKER CERTIFIED SOLUTION
Avatar of cameroncooke
cameroncooke
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial