title: Stop execution of function after fixed time in javascript
body: <p>I need to let a function run for a fixed number of seconds, then terminate. I could use jQuery or web workers, but my attempt at doing it directly faild. </p>
  
  <p>Tks for help this now works:</p>
  
  <pre><code>startT = new Date().getTime();
  i = 1;
  
  while(true){
      now = new Date().getTime();
      if( (now - startT) &gt; 100) {
          break;
      } 
  
      i++;
  }
  
  alert(i);
  </code></pre>