gpt4 book ai didi

Javascript 不会自动刷新 iframe

转载 作者:行者123 更新时间:2023-12-03 08:58:38 28 4
gpt4 key购买 nike

我想要一个 iframe 每 5 秒刷新一次,但它不起作用,我不明白为什么?我手动更改了文本文件,但它不会在网站上自动刷新。文本文件有什么特别之处吗?

<!DOCTYPE html>
<html>
<head>
<title>Example</title>
</head>
<body>
<script>
window.setInterval("reloadIFrame();", 5000);
function reloadIFrame() {
document.frames["knasFrame"].location.reload();
}
</script>
<iframe name="knasFrame" src="output.txt"></iframe>
</body>
</html>

最佳答案

<!DOCTYPE html>
<html>
<head>
<title>Example</title>
</head>
<body>
<script>
window.setInterval("reloadIFrame();", 5000);
function reloadIFrame() {
document.getElementsByName("knasFrame")[0].contentWindow.location.reload();
}
</script>
<iframe name="knasFrame" src="output.txt"></iframe>
</body>
</html>

关于Javascript 不会自动刷新 iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32383555/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com