Safari Javascript Image Reload Issue

Posted on 2012-03-24
Last Modified: 2012-03-24
I need to get an image to refresh itself via JavaScript instead of reloading the page.

This code:

<!DOCTYPE html>

<script type="text/javascript" language="JavaScript">
refreshImage = function()
document.getElementById('cam').setAttribute('src', '');
document.getElementById('cam2').setAttribute('src', '');



<center><img src="" id="cam" alt="Image" width="640" height="480" onload="setInterval(refreshImage, 1);"></center><br>
<center><img src="" id="cam2" alt="Image1" width="320" height="240" onload="setInterval(refreshImage, 1);"></center>


Open in new window

Works everywhere except for Safari, which I need it to work in.
What could I possible be doing wrong?
It loads the initial image but won't reload.
Question by:dxanon
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 75

Accepted Solution

Michel Plungjan earned 500 total points
ID: 37761470
every time you load the image, you start an interval. That interval is every millisecond - no way can the cam load that fast and you make interval after interval.

Try this code
<!DOCTYPE html>

<script type="text/javascript" language="JavaScript">
var tId;
window.onload=function() {
  tId=setInterval(function() {  
    document.getElementById('cam').setAttribute('src', ''+new Date().getTime());
    document.getElementById('cam2').setAttribute('src', ''+new Date().getTime());
  },1000); // milliseconds so I would suggest 3000 or so



<center><img src="" id="cam" alt="Image" width="640" height="480" /></center><br>
<center><img src="" id="cam2" alt="Image1" width="320" height="240" /></center>


Open in new window


Author Closing Comment

ID: 37761474
That worked wonderfully, I was actually able to tweak it to around 500 and it works great on the iPad.  Thanks for the quick response I was going crack!.
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37761508
YW. Off to bed

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Adding a countdown to HTA 12 99
How to check or uncheck a checkbox using the id of the checkbox 2 21
null, truthy, falsey confusion 25 33
HTML editor custom button 3 60
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question