javascript - 在 Chrome 控制台上重新加载后保持 Javascript 运行

标签 javascript google-developers-console

所以,我想每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/

相关文章:

javascript - Node js错误[ERR_HTTP_HEADERS_SENT] : Cannot set headers after they are sent to the client and no javascript object in console

google-api - 如何避免 Gmail API 集成的安全评估

google-analytics - 是否可以为 Google 帐户创建服务帐户并以编程方式获取 p12 key ?

google-api - 通过 HTTP 引荐来源网址(客户端)或 IP 地址(服务器端)限制 Google API key

javascript - 将经典 ASP session 变量获取到内联 JavaScript

javascript - canplaythrough 事件和 HTM5 音频 : can anyone remove this event?

android - Google Play Android 应用内部测试 - 内部测试人员未显示更新按钮

android - 我是否需要为每个 productFlavor 创建一个新的 google-services.json?

javascript - d3 - 如何显示持续时间间隔而不是tickValues

javascript - JS功能只有在点击屏幕后才能正常工作