refreshing an iframe by the parent site goes wrong

Hello Experts,

Two sites (parent.asp and view.asp) the view.asp is shown as a iframe of parent.asp. View.asp has a onclick event on the body tag:

onclick="parent.SetStatus('<% response.write IP %>','<% response.write size %>','<% response.write leds %>','<% response.write iframe %>');"

and the set status function is attached as code sniplet beneath.
At the end of this script the Iframe (iframe1) has to be reloaded but all I've tried did not have any success
.
And the overall functionality needs this refresh to reload a part asp code in the top of the view.asp site.
When I put <meta http-equiv="refresh" content="300"> in the view.asp the functionality works. But I need only one refresh after the script action. Maybe there has to be a small pauze between the script action and the reload of the site.

Can someone please tell me what I am doing wrong?

I.ve tried to ad the following lines to the script (one by one):

 document.getElementById("iframe1").src=document.getElementById("iframe1").src;
window.setTimeout("window.location.reload(true)", 30000);
document.iframe1.src=document.iframe1.src
document.getElementById("iframe1").location.reload();
top.frames.iframe1.location.reload();
parent.parent.iframe1.location.reload()">

with (document.getElementById("Frame3").location)
 {
 href = href;
 }


<script language="Javascript">
function SetStatus(IP,size,leds,iframe)
{
 document.frames["iframeB"].location.href = "http://" + IP + "/control/control?set&section=general&size="+size;
 document.frames["iframeC"].location.href = "http://" + IP + "/control/rcontrol?action="+leds;
}
</script>

Open in new window

LVL 1
SteynskAsked:
Who is Participating?
 
bluV11tConnect With a Mentor Commented:
Hi!
I think the src-reassignment is your best bet. Just make a function of it and add a timer




In head tag of parent:
 
    <script language="JavaScript">
        function reloadIframe(myFrameID){
                   var tail='&r='+Math.round(Math.random*10000);
                    document.getElementById(myFrameID).src=document.getElementById(myFrameID).src+tail; 
        }
</script>
 
At the end of SetStatus function:
(A 3 sec delay)
 
           window.setTimeout("reloadIframe('iframe1');", 3000);

Open in new window

0
 
bluV11tCommented:
Hi!
Try
document.getElementById('iframe1').contentDocument.location.reload(true);
0
 
bluV11tCommented:
Sorry, that only works in FF. Found this that works in IE8 but not FF

window.frames[FrameID].window.location.reload();

Also you could try reassigning the src but with an added tail to the url:

           var tail='&r='+Math.round(Math.random*10000);
            document.getElementById('myIframe').src=document.getElementById('myIframe').src+tail;

Just make sure you already have a querystring variable in the iframe url, it doesn't have to do anything.

0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
bluV11tCommented:
That should be
            document.getElementById('iframe1').src=document.getElementById('iframe1').src+tail;
0
 
SteynskAuthor Commented:
No this is not solving the problem Maybe the refresh is to quick. After the action.
What should be the syntax if we should delay this refresh?
something like:??

window.setTimeout("document.getElementById('iframe1').contentDocument.location.reload(true);", 30000);
or
setTimeout("document.getElementById('iframe1').contentDocument.location.reload(true)", 30000);

both don't refresh the screen after x seconds.
Strange becouse when when I put periodic refresh in view.asp it refreshes without problem and this makes the overall page function like it should.
Maybe the other code in de view.asp has its influence on the refresh

Could you please have a look? the "xmlhttp" code is needed for the functionality

<% 
dim IP, LOC, url, size, leds
IP = Request.QueryString("IP")
LOC = Request.QueryString("loc")
iframe = Request.QueryString("iframe")
%>
<html>
<head>
<title><% response.write LOC %></title>
<%
url = "http://" & IP & "/control/control?read&section=imagecontrol&size"  
    set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")  
    on error resume next 
    xmlhttp.open "GET", url, false 
    xmlhttp.send ""  
        if instr(xmlhttp.responseText,"640x480")>0 then
        	size="800x600"
        	leds="ledsdefault"
        else
        	size="640x480"
        	leds="ledsoff"
        end if 
     set xmlhttp = nothing %>
</head>
<body bgcolor=black onclick="parent.SetStatus('<% response.write IP %>','<% response.write size %>','<% response.write leds %>','<% response.write iframe %>');" onload="if (document.all && document.all.CamPic) document.all.CamPic.style.width='auto';animation_init();"> 
<noscript>
        <center>
                <font face="Helvetica,Arial" size="+1" color=red>
                        Sta het gebruik van Javascripten toe om bewegend beeld te krijgen <br>Please allow the use of javascripting to receive motion picture.
                </font>
        </center>
</noscript>
 
<br><div align=center>
<form name="dkdk">
<TABLE cellpadding=0 border=0 cellspacing=0>
<TR  valign=baseline>
<td colspan=2 align=center>
<img name="CamPic" src="http://" & <% response.write IP %> & "/record/current.jpg?rand=6014151" ALT="<% response.write LOC %>" TITLE="<% response.write LOC %>" width="320" height="240"></td>
</tr>
<tr>
<td>
 
<script language="JavaScript" type="text/javascript">
        var current_refresh_method_nr=0;
        var refreshmethods_type=new Array(0,0,0,1,2);
        function refreshMethod(new_value) {
                if (refreshmethods_type[new_value]!=refreshmethods_type[current_refresh_method_nr]) {
                        var url=location.href.split("?");
                        location.href=url[0]+"?REFRESHMETHOD="+new_value;
                } else {
                        current_refresh_method_nr=new_value;
                        setframerate();
                }
        }
</script></td>
</TR>
</TABLE>
</form></div>
<script language="JavaScript">
                        var pic_url="http://<% response.write IP %>/record/current.jpg";
                        var noframepath="http://<% response.write IP %>/decor/m1m-error.jpg";
                        var n=Math.floor(Math.random()*1000000);
                        var session_id=Math.floor(Math.random()*1000000);
                        var startn=n;
                        var GetItOn=1;
                        var framerate=2;
                        var buffer= new Image();
                        var aktiv=null;
                        var db_enabled=0;
                        var passiv=null;
 
  function DoComplete()
  {
                if (db_enabled != 0) {
                        if (db_enabled<0) {
                                //document.CamPic.style.filter="";buffer.style.filter="alpha(opacity=70,style=0)";
                                document.CamPic.style.display="";
                                buffer.style.display="none";
                        } else {
                                //document.CamPic.style.filter="alpha(opacity=70,style=0)";buffer.style.filter="";
                                buffer.style.display="";
                                document.CamPic.style.display="none";
                        }
                        db_enabled*=-1;
                } else {
                document.CamPic.src = buffer.src;
                }
                GetItOn = 1;
                if (current_refresh_method_nr == 1 && framerate>0) {// Sync onload implementieren
                        if (passiv==null)
                                Animation();
                }
  }
        function LoadError()
        {
                if (db_enabled != 0) {
                        db_enabled*=-1;
                } else {
                        document.CamPic.src=noframepath;
                }
                GetItOn = 1;
                if (current_refresh_method_nr == 1 && framerate>0) // Sync onload Fehlerbehandlung
                        passiv=setTimeout("passiv=null;Animation();",1000);
        }
 
  function setframerate(value) {
                framerate=value;
                if (aktiv) {
                        window.clearInterval(aktiv);
                        aktiv = null;
                }
                document.CamPic.onerror=null;
                buffer.onerror=null;
                if (framerate<0) {
                        if (current_refresh_method_nr == 2) { //  Stream ausschalten
                                GetItOn=1; Animation();
                        }
                        return;
                }
                // Refresh Typen
                if (current_refresh_method_nr == 2) { //  Stream anschalten
                        buffer.onload = null;
                        buffer.onerror= null;
                        document.CamPic.onload=null;
                        // wg. Mozilla Bug # 42224 "Spontaner Abbruch des Streams"
                        document.CamPic.onerror= function () {setTimeout("setframerate();",500) } ;
                        document.CamPic.src = "http://<% response.write IP %>/cgi-bin/faststream.jpg?stream=full&fps="+framerate+"&rand=" + String(n++);
                        return;
                } else if (current_refresh_method_nr == 1) { // OnLoad synced
                        session_id++;
                        Animation();
                        return;
                }
                aktiv=window.setInterval("Animation()",1000/framerate);
                GetItOn=1;      // auf alle Faelle anzeigen!
                Animation(); // und go...
        }
  function Animation()
  {
                var my_rm_nr=current_refresh_method_nr;
                var my_fr=framerate;
                var my_session=session_id;
 
          if (GetItOn == 1 || (my_rm_nr == 1 && my_fr>0))
                        // Bild ist geladen und das naechste kann
          {     // angefordert werden.
                        GetItOn = 0;
                        if (db_enabled<0) {
                                buffer.onerror=buffer.onload=null;
                                document.CamPic.onerror= LoadError;
                                document.CamPic.onload = DoComplete;
                                if (my_rm_nr == 0)
                                        document.CamPic.src = pic_url + "?rand=" + String(n++);
                                else
                                        document.CamPic.src = pic_url + "?sync="+my_fr+"&session="+my_session+"&rand="+String(n++);
                        } else {
                                document.CamPic.onerror=document.CamPic.onload=null
                                buffer.onerror= LoadError;
                                buffer.onload = DoComplete;
                                if (my_rm_nr == 0)
                                        buffer.src = pic_url + "?rand=" + String(n++);
                                else
                                        buffer.src = pic_url + "?sync="+my_fr+"&session="+my_session+"&rand="+String(n++);
                        }
                }
  }
  function animation_init() {
                if ( document.all
                                && (navigator.platform.substr(0,3) != "Mac")
                                && (document.CamPic.inserAdjacentHTML)
                                 ) {
                        document.CamPic.insertAdjacentHTML("AfterEnd","<img border=0 style=\"display:none;\" name=dbbuffer><\/b>");
                        buffer=document.dbbuffer;
                        db_enabled=1;
                }
                setframerate(framerate);
        }
</script>
</font>
<script type='text/javascript' language='JavaScript'>self.focus();</script></body>
</html>

Open in new window

0
 
bluV11tCommented:
This is view.asp right?
Could you post code for parent.asp?
Also, could you do an alert at the end of the SetStatus function to make sure it gets there?
0
 
SteynskAuthor Commented:
bluV11t

The alert showed me a sytax error. The two script commands that are API commands for a web cam and switches it to another status were execued in IframeB and IframesC but this should be IframeA and IframesB
Therefore the refresh did not execute.

Thanks for that.
What should be the most likely command to execute the refresh now?  Because I don't like to try them all again.
And I still think we have to put in an timeout on that command because the came is still processing the API command and would possiblay not be ready to produce the right info for the proces.
That could do it or it looks like the value's of the variarables are cashed and re-used.

the code is from the parent site.

 
<html>
<head>
 
 
<title></title>
<script language="Javascript">
function SetStatus(IP,size,leds,iframe)
{
 document.frames["iframeA"].location.href = "http://" + IP + "/control/control?set&section=general&size="+size;
 document.frames["iframeB"].location.href = "http://" + IP + "/control/rcontrol?action="+leds;
document.getElementById("iframe1").src=document.getElementById("iframe1").src;
}
</script>
</head>
<body bgcolor=black>
<table cellpadding=0 border=0 cellspacing=0>
<tr>
<td colspan=4><iframe ID="iframeA" src ="URL1" width="100%"></iframe><iframe ID="iframeB" src ="URL2" width="100%"></iframe></td>
</tr>
<tr>
<td><iframe ID="iframe1" src ="view.asp?IP=192.168.1.28&iframe=iframe1&loc=Noord-1" scrolling=no border="0" frameborder="0" width="320" height="240"></iframe></td>
<td><iframe ID="iframe2" src ="view.asp?IP=192.168.1.29&iframe=iframe2&loc=Noord-2" scrolling=no border="0" frameborder="0" width="320" height="240"></iframe></td>
<td><iframe ID="iframe3" src ="view.asp?IP=192.168.1.30&iframe=iframe3&loc=Noord-3" scrolling=no border="0" frameborder="0" width="320" height="240"></iframe></td>
<td><iframe ID="iframe4" src ="view.asp?IP=192.168.1.31&iframe=iframe4&loc=Noord-4" scrolling=no border="0" frameborder="0" width="320" height="240"></iframe></td>
</tr>
<tr>
<td><iframe ID="iframe5" src ="view.asp?IP=192.168.1.32&iframe=iframe5&loc=Noord-5" scrolling=no border="0" frameborder="0" width="320" height="240"></iframe></td>
<td><iframe ID="iframe6" src ="view.asp?IP=192.168.1.33&iframe=iframe6&loc=Noord-6" scrolling=no border="0" frameborder="0" width="320" height="240"></iframe></td>
<td><iframe ID="iframe7" src ="view.asp?IP=192.168.1.34&iframe=iframe7&loc=Noord-7" scrolling=no border="0" frameborder="0" width="320" height="240"></iframe></td>
<td><iframe ID="iframe8" src ="view.asp?IP=192.168.1.35&iframe=iframe8&loc=Noord-8" scrolling=no border="0" frameborder="0" width="320" height="240"></iframe></td>
</tr>
<tr>
<td><iframe ID="iframe9" src ="view.asp?IP=192.168.1.36&iframe=iframe9&loc=Noord-9" scrolling=no border="0" frameborder="0" width="320" height="240"></iframe></td>
<td><iframe ID="iframe10" src ="view.asp?IP=192.168.1.37&iframe=iframe10&loc=Noord-10" scrolling=no border="0" frameborder="0" width="320" height="240"></iframe></td>
<td><iframe ID="iframe11" src ="view.asp?IP=192.168.1.38&iframe=iframe11&loc=Noord-11" scrolling=no border="0" frameborder="0" width="320" height="240"></iframe></td>
<td><iframe ID="iframe12" src ="view.asp?IP=192.168.1.39&iframe=iframe12&loc=Noord-12" scrolling=no border="0" frameborder="0" width="320" height="240"></iframe></td>
</tr>
</table>
</body>
</html>

Open in new window

0
 
SteynskAuthor Commented:
That was it. You earned every point of it.
Thanks a lot. The solution is my last part of a very big functionality and it is going to be used for a very good cause. The (touch screen)webpage is going to be used on a prenatal department of our hospital and it will give  the staff an easy to use interface to manage 2x 12 web cams.
The cams will be used to give parents a way to see their kids.
Thanks a lot.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.