定时刷新网页出错:Refused to display '' in a frame because it set 'X-Frame-Options' to 'deny'.

GingerbreadMan 2025-04-05 21:07:38

网上找到一段代码,定时刷新网页。
刷新目标网站时报错,目标网页不支持在iframe中加载:
Refused to display '<URL>' in a frame because it set 'X-Frame-Options' to 'deny'.
代码如下:
var timeout = prompt("Set timeout (Second):");
var count = 0;
var current = location.href;
if (timeout > 0) {
setTimeout('reload()', 1000 * timeout);
} else {
location.replace(current);
}
function reload() {
count++;
console.log('每(' + timeout + ')秒自动刷新,刷新次数:' + count);
var fr4me = '<frameset cols="*"><frame src="' + current + '"/></frameset>';
with(document) { write(fr4me); void(close()) }
setTimeout('reload()', 1000 * timeout);
请教如何改进?只需要能在浏览器控制台执行定时刷新的代码就行。

...全文
116 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
trainee 04-07
  • 打赏
  • 举报
回复

网页被设定为禁止FRAME加载,那就不要FRAME,

var fr4me = ' src="' + current + '"';

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧