Note that there are some explanatory texts on larger screens.

plurals
  1. POWaiting for Javascript function completion in HTML
    text
    copied!<p>How to ensure that a Javascript function is finished before moving on to the next line in the HTML code.</p> <p>For eg : I am having a Javascript code in <code>main()</code> and calling tht as shown below. Before this finish off, the next line of HTML code like loading a JPEG is showing up in the webbrowser. Is there any way I could ensure the <code>main()</code> call is executed completely. </p> <pre><code>&lt;script language="JavaScript" type="text/javascript"&gt; main();&lt;/script&gt; </code></pre> <p>As some of you guessed correctly,There is an asynchroous call within the main() which uses a XMLHTTPRequest() to get some of the values I need to form the webpage. The function main is a s below</p> <pre><code>function main() { var requestor = new net.Requestor("admin/getparam.cgi?mainvideostream&amp;codectype", CurrentHandler); } </code></pre> <p>and net.Requestor=function(url,onload,onerror,method,params,contentType) within this thers is and XMLHTTPRequest(...)</p> <p>And the Currenthandler is another function which deals with the response from the requset.</p> <pre><code> function CurrentHandler() { settings = this.req.responseText.split("\n"); for(var j=0; j&lt;settings.length-1; j++) { var currentST= settings[j].split("="); name = currentST[0]; value = currentST[1]; switch(name) { case "mainvideostream": cur_camid = value; break; case "codectype": stream = value; break; } } mainSection(); } </code></pre> <p>So I have to find out the stream variable before loading the page.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload