所以,我想每15秒检查一下某个网站上是否有一些单词被删除。 我已经这样做了:
window.setInterval(myFunction, 15000)
function myFunction()
{
//Check that "words" are not on web anymore
if ((document.documentElement.textContent || document.documentElement.innerText).indexOf('words') > -1)
{
alert("They still here");
}
else
{
alert("They are gone");
}
location.reload();
}
但是由于location.reload();
,它们的脚本只能运行一次。
我该怎么办?
最佳答案
在 window.load 中调用计时器并删除位置的重新加载。
window.onload = function() {window.setInterval(myFunction, 15000)};
function myFunction()
{
//Check that "words" are not on web anymore
if ((document.documentElement.textContent || document.documentElement.innerText).indexOf('words') < -1)
{
alert("They are gone");
}
}
关于javascript - 在 Chrome 控制台上重新加载后保持 Javascript 运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67355784/