title: redirect to html from cgi once the page is fully written
body: <p>I have searched for a case similar to mine and found few related posts but none of them could answer my question.</p>
  
  <p>The cgi script I'm executing is crunching some numbers and at the end is spiting out a html file. I am controlling the location of this html file and providing a url to it on a transient website that is displayed upon successful submission of the html form.</p>
  
  <p>The output html is created within a moment, or it is not created instantly in other words.</p>
  
  <p>Is there a way to check within my temporary cgi page, whether the html has been fully written and then redirect to it automatically? If the page isn't ready I would like user to stay on the current page.</p>
  
  <p>At the moment on my temporary cgi page I display 'check' and 'terminate' buttons where you can check for the status/terminate it. When 'check' is clicked and the website is ready then I redirect to it.
  Also I display a url to the html file which you can go to but will be presented with just a fragment of the page if followed immediately.</p>
  
  <p>I would like the refresh/redirect to be automatic so user doesn't have to click on anything.</p>
  
  <p>I've seen elsewhere an idea to 'try to load a known small image and you detect if the loading is done or not':</p>
  
  <pre><code>&lt;img src="http://www.example.com/image.jpg"
    onload="window.location='http://www.example.com';"
    onerror="window.location='#';"&gt;
  </code></pre>
  
  <p>I like that, but it's not perfect. My temporary cgi page won't pass further the url to the results html without submitting a form (no GET, no POST here, since no form is used). Once again I would like the redirecting to be as automatic as possible.</p>
  
  <p>So to summarize: how can I check from within a page generated with the CGI.pm whether outside html page is ready to be redirected to?
  Is the DWR (<a href="http://directwebremoting.org" rel="nofollow">http://directwebremoting.org</a>) the only solution?</p>
  
  <p>I would be happy to accept some JavaScript solutions.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I start writing to the result page right after the initial form is submitted and keep adding to it on the fly.
  It is rather not easy/possible to check for the non-404 response (and then redirect) as already suggested since the page exists from the beginning (but is not complete).</p>