title: Auto refresh JavaScript function stop working after some time
body: <p>i need to refresh image in every 5 sec. without flicker. so search google and find some solution.
  but that Code refresh image and without flicker but it stop refresh image after some time.
  some time its stop refresh image after 1 min, some time after 3 min some time after 15 min.</p>
  
  <p>Here is my code</p>
  
  <pre><code>&lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;&lt;/title&gt;
  
  &lt;script language="JavaScript"&gt;
  var x = 0,
      y = 0;
  var canvas, context, img;
  
  function timedRefresh() {
      canvas = document.getElementById("x");
      context = canvas.getContext("2d");
      img = new Image();
      img.src = "CC4.png?" + Math.random();
      img.onload = function () {
          context.drawImage(img, x, y);
          x += 0;
          y += 0;
          setTimeout('timedRefresh()', 5000);
      };
  }
  window.onload = timedRefresh;
  
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body id="home" onload="setTimeout('timedRefresh()',5000)"&gt;
  &lt;canvas id="x" width="800" height="590"/&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>