如何自动每分钟重新加载一个网页?

时间:2017-05-22 08:28:55

标签: javascript google-chrome-devtools

我是Chrome开发者工具的新手。 我想要一个简单的事情:

如何使用chrome开发者控制台中的某些脚本每分钟重新加载一些网页(例如,pinterest或twitter页面)?

2 个答案:

答案 0 :(得分:0)

这是一个可用于刷新任何页面的功能。

首先复制粘贴此功能 -

function refresh(secs) {
  document.documentElement.innerHTML = '<body style="margin:0px;padding:0px;overflow:hidden"><iframe frameborder="0" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;height:100%;width:100%;position:absolute;top:0px;left:0px;right:0px;bottom:0px" height="100%" width="100%" id="p" src="' + window.location.href + '"></iframe></body>'
  setInterval(() => document.getElementById('p').src = document.getElementById('p').src, secs * 1000)
}

然后像这样使用它 -

refresh(10) // refresh every 10sec

您可以传递任何其他数字,以秒为单位自定义刷新间隔。

这基本上做的是将当前页面放在iframe中,然后定期刷新它。

答案 1 :(得分:0)

您还可以在正在使用的html页面中使用setTimeout函数或metaTag。 我喜欢使用meta标签它很简单。

<meta http-equiv="refresh" content="2";>

以下是有关它的更多信息的链接。     https://www.w3schools.com/tags/att_meta_http_equiv.asp

相关问题