如何每5秒更换一次Google Chrome扩展程序中的网页内容?

时间:2012-01-26 11:04:05

标签: google-chrome google-chrome-extension google-chrome-devtools

我正在编写一个简单的Chrome扩展程序,它应该每隔5秒替换一次网页的特定内容?

是否有可能做到这一点?

这是我的功能(这将取代特定内容)

replaceText(document.body.innerHTML);

如何在我的脚本'myscript.js'中每x秒运行一次这个函数?

2 个答案:

答案 0 :(得分:1)

最简单的方法是使用setTimeout。它看起来像这样:

function timedFunction() {
    replaceText(document.body.innerHTML);
    setTimeout("timedFunction()",5000);
}

timedFunction();

答案 1 :(得分:0)

您可以使用setTimeout()

请参阅w3schools timing events reference