Solved

Safari Javascript Image Reload Issue

Posted on 2012-03-24
3
721 Views
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>

<html>
<head>
<script type="text/javascript" language="JavaScript">
refreshImage = function()
{
document.getElementById('cam').setAttribute('src', 'http://192.168.1.81/image.jpg?width=2560&height=1920&denom=3');
document.getElementById('cam2').setAttribute('src', 'http://192.168.1.81/image.jpg?width=2560&height=1920&denom=3');
document.getElementById('cam2').reload();
document.getElementById('cam1').reload();

}
</script>

</head>
<body>

<center><img src="http://192.168.1.81/image.jpg?width=2560&height=1920&denom=3" id="cam" alt="Image" width="640" height="480" onload="setInterval(refreshImage, 1);"></center><br>
<center><img src="http://192.168.1.81/image.jpg?width=2560&height=1920&denom=3" id="cam2" alt="Image1" width="320" height="240" onload="setInterval(refreshImage, 1);"></center>

</body>
</html>

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.
0
Comment
Question by:dxanon
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
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>

<html>
<head>
<script type="text/javascript" language="JavaScript">
var tId;
window.onload=function() {
  tId=setInterval(function() {  
    document.getElementById('cam').setAttribute('src', 'http://192.168.1.81/image.jpg?width=2560&height=1920&denom=3&rnd='+new Date().getTime());
    document.getElementById('cam2').setAttribute('src', 'http://192.168.1.81/image.jpg?width=2560&height=1920&denom=3&rnd='+new Date().getTime());
  },1000); // milliseconds so I would suggest 3000 or so
}

</script>

</head>
<body>

<center><img src="http://192.168.1.81/image.jpg?width=2560&height=1920&denom=3" id="cam" alt="Image" width="640" height="480" /></center><br>
<center><img src="http://192.168.1.81/image.jpg?width=2560&height=1920&denom=3" id="cam2" alt="Image1" width="320" height="240" /></center>

</body>
</html>
                                  

Open in new window

0
 

Author Closing Comment

by:dxanon
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!.
0
 
LVL 75

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
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 …

914 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now