Javascript and google Chrome -
when i'm executing javascript code in loop on google chrome console, every javascript things on page not work because i'm on loop. there way have infinite loop on script , continue have web page working fine ? have use kinds of threads ? thanks, xavier
no, don't have multiple javascript threads in browser window.
if executing tight loop, browsers may either lock because javascript process freezes ui, or may detect loop , kill it. chrome this, , newer versions of internet explorer. if browser did not intervene , allow user kill script other methods killing process or restarting machine. (tight loop example: while(2+2!==5);
)
if want things @ regular intervals - animation - use setinterval call function every many milliseconds. can in loop maintaining simple loop counter.
example:
function blink(el) // millenials won't { el.blink_visible = !el.blink_visible; el.style.visibility = el.blink_visible ? 'visible' : 'hidden'; } var label = document.getelementbyid('label'); var delayms = 500; // delay in milliseconds setinterval(blink, delayms, label);
<h1 id='label'>hello world</h1>
you can set milliseconds low , away it, depends on doing in function called @ each iteration.
Comments
Post a Comment