Image Refresh from js file
Hello,
I have following HTML page (index.html)
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 STRICT//EN" "DTD/xhtml1-strict.dtd">
<HTML>
<HEAD>
<TITLE></TITLE>
<LINK rel=stylesheet type=text/css href="css/bwc.css">
<SCRIPT type=text/javascript src="jscript/twoway.js"></SCRIPT>
<SCRIPT type=text/javascript src="jscript/functions.js"></SCRIPT>
<SCRIPT type=text/javascript src="jscript/refresh.js"></SCRIPT>
<SCRIPT type=text/javascript>
var useUDP = false;
var myGUIGroup = 'NewGUIGroup';
function loadWebImages(){
var img;
img = document.getElementById('img0');
if (img){
img.src = 'http://192.168.0.252/images1sif';
}
}
</SCRIPT>
</HEAD>
<!-- bwc generated code start -->
<BODY BGCOLOR="Black" style="WIDTH:640px; HEIGHT:480px; sPOSITION: absolute; MARGIN-TOP: 0px; MARGIN-LEFT: 0px; -webkit-user-select: none;" onorientationchange = onRotate(orientation); onunload=allowAJAX=false; >
<IMG style="POSITION:absolute; TOP:24px; LEFT:32px; WIDTH:564px; HEIGHT:427px;" id="imgPL0" src="images/webImgPlaceholder.jpg" alt="Web Image" > <!-- 03.13.2011 04:15:48 -->
<IMG style="POSITION:absolute; TOP:24px; LEFT:32px; WIDTH:564px; HEIGHT:427px;" id="img0" src="" alt="Web Image" > <!-- 03.13.2011 04:15:48 -->
<!-- bwc generated code end -->
</BODY>
</HTML>
and a .js files called refresh.js
Code:
<!--
function refresh(){
var image = "http://192.168.0.252/images1sif"
document.images["img0"].src=image+"?"+new Date();
setTimeout('refresh()', 120);}
if(document.images)window.onload=refresh;
// -->
The code above will refresh the image all the time. (that's what I want)
However, as you can see in the js file 'var image = http://...' I want to get the URL of the image from the index.html page (img.src = 'http://...)
Code:
var image = "http://192.168.0.252/images1sif"
Code:
<IMG style="POSITION:absolute; TOP:24px; LEFT:32px; WIDTH:564px; HEIGHT:427px;" id="img0" src="" alt="Web Image" >
I know it has src="" but I want to read it from the function loadWebImages
Code:
function loadWebImages(){
var img;
img = document.getElementById('img0');
if (img){
img.src = 'http://192.168.0.252/images1sif';
}
The index.html page gets created from a program which we can't edit so everything needs to be done from the refresh.js file.
I have trying to find a way but can't work it out.
Can someone help me out with this?
Aaron.
Re: Image Refresh from js file
Is the index.html page which from which you are obtaining the data on a different domain than refresh.js? If so, then you cannot do this in the way you've due to security reasons.
You'll need to use jQuery to do a cross-domain AJAX call. Then parse out the src value with regular expressions. See this page for more information.
Re: Image Refresh from js file
Hello,
The 2 files are in the same place.
The index.html is created using a computer program, which I can't edit. I need to do all my calling etc from the refresh.js file.
That is where I need help calling the src from the js file.
Since the src is from a function on the index.html I need to find a way of reading the data from that function.
Any ideas?
Aaron.