Solved

Safari Javascript Image Reload Issue

Posted on 2012-03-24
3
766 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
[X]
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
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This article discusses how to implement server side field validation and display customized error messages to the client.
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 and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

688 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