Home  >  Q&A  >  body text

javascript - Conflict between setInterval and document.write under IE browser

function reload(){
    alert("ce");
}
window.onload=function(){
    alert("a");
    setInterval("reload()",1000);
    document.write("aaa");
};

As above, there is no problem in other fast browsers and chrome kernel browsers with setInterval and document.write at the same time. But in IE11 browser, setInterval will stop. How to deal with it. Thanks.

世界只因有你世界只因有你2662 days ago982

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-07-05 10:50:22

    document.write will implicitly call document.open. This will reconstruct the document, removing all event events and task.

    You can use document.body.innerText instead of document.write

    function reload(){
        alert("ce");
    }
    window.onload=function(){
        alert("a");
        setInterval("reload()",1000);
        document.body.innerText = "aaa";
    };

    reply
    0
  • Cancelreply