?
Solved

Safari Javascript Image Reload Issue

Posted on 2012-03-24
3
Medium Priority
?
779 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 2000 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

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
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 modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Suggested Courses

770 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