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
Solved

Safari Javascript Image Reload Issue

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

856 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