您的位置:首頁技術文章
文章詳情頁

javascript - setInterval和document.write在IE瀏覽器下的沖突

瀏覽:111日期:2023-03-22 08:20:56

問題描述

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

如上,同時有 setInterval 和 document.write在其他極速瀏覽器,chrome內核瀏覽器里沒有問題。但是在 IE11 瀏覽器里,setInterval 就會停止。怎么解決。謝謝。

問題解答

回答1:

document.write會隱式調用document.open。這樣會重構document,移除所有event事件和task。

可以用document.body.innerText代替document.write

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

標簽: JavaScript
相關文章:
国产综合久久一区二区三区