/    Sign up×
Community /Pin to ProfileBookmark

looking for help with auto refresh image script

hi all,

first i guess it best i explain what i am trying to do and then what i have done so u can hopefully point out my mistakes..

atm i have a webserver setup at home ( local only) and an internal ftp program running on the webserver… i have an ip camera ( mobotix) ftping images every 1 second to the webserver and puting the jpg image in a folder called testpic…

what i am trying to do is get a script working so that it auto refreshes the image every second ….

so what i have done.. well i have this script:

[CODE]<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
<script language=”JavaScript”><!–
function refre****() {
if (!document.images) return;
document.images[‘myCam’].src = ‘testpic/image1.jpg’ + Math.random();
setTimeout(‘refre****()’,1000); // refresh every 1 secs
}
//–></script>
</head>

<body onLoad=” setTimeout(‘refre****()’,1000)”>
<div align=”center”>
<table width=”640″ border=”0″ cellpadding=”0″ cellspacing=”0″>
<!–DWLayoutTable–>
<tr>
<td width=”640″ height=”480″ valign=”top”><img src=”testpic/image1.jpg” name=”myCam” width=”640″ height=”480″ />&nbsp;</td>
</tr>
</table>
</div>
</body>
</html>
[/CODE]

the code seems to be ** out the refresh it part of the code, so where it says refr**** it is refresh it with out a space…

this basic site puts a copy of the image1.jpg in the middle of the screen and then refresh it every second. but for some reason it displays the first one then when it refreshes the image there is no picture just the box with a cross.. now i know that the image has updated in the testpic file cus i can F5 the page to display the new image that the script should have loaded.

can anyone be a massive help and point out where i could be going wrong?

thanks for any help at all

Vade

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@VadeauthorNov 29.2007 — Anyone got an idea on this?

thanks
Copy linkTweet thisAlerts:
@yearbassNov 29.2007 — when you got no picture and just the box with a cross, look at your code:
[CODE]
document.images['myCam'].src = 'testpic/image1.jpg' + Math.random();[/CODE]


it wouldn't display anything, unless you erase "+ Math.random()".

I never success to refresh the image with same name with javascript (although it actually different in content), because the browser cache (i guess), i need to refresh the browser to see the changes. the best practice is using iframe, inside the iframe there is html page displaying your image and refersh every second.
[CODE]
<iframe src="imgCam.html" width="300" height="300"></iframe>[/CODE]


and the imgCam.html
[CODE]<html>
<head>
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="expires" content="-1000" />
<meta http-equiv="refresh" content="1"/>
</head>
<body style="margin:0px;">
<img src="image1.jpg" width="250" height="250"/>
</body>
</html>[/CODE]


if you or anyone find the solution with javascript, please let me know ?
Copy linkTweet thisAlerts:
@usefulcoffeeSep 07.2011 — thank you for this solution my friend.
×

Success!

Help @Vade spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...