如何刷新嵌入式网站?
How can you refresh an embedded site?
我不知道如何使用 vanilla JavaScript 刷新嵌入页面。我尝试了以下方法,但似乎不起作用
<html>
<iframe src="https://flowlab.io/game/play/1987226" width="100px" height="100px" id="HI" />
<script>
function refreshIFrame() {
var x = document.getElementById("HI");
x.contentWindow.location.reload();
}
function sleep(milliseconds) {
const date = Date.now();
let currentDate = null;
do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
}
refreshIFrame();
sleep(1000);
</script>
</html>
不确定你想用这个来完成什么,但下面的方法会起作用。使用 setInterval 进行计时。我添加了缓存破坏器以备不时之需。
<iframe src="https://flowlab.io/game/play/1987226" style="width:1000px;height:600px;" id="HI"></iframe>
<script>
function refreshIFrame() {
console.log('Refresh');
var x = document.getElementById("HI");
//to help prevent cached reload, add a cache buster
const cb = new Date().getTime();
x.contentWindow.location.href = "https://flowlab.io/game/play/1987226?cb=" + cb;
}
setInterval(function() {
refreshIFrame();
}, 1000)
</script>
我不知道如何使用 vanilla JavaScript 刷新嵌入页面。我尝试了以下方法,但似乎不起作用
<html>
<iframe src="https://flowlab.io/game/play/1987226" width="100px" height="100px" id="HI" />
<script>
function refreshIFrame() {
var x = document.getElementById("HI");
x.contentWindow.location.reload();
}
function sleep(milliseconds) {
const date = Date.now();
let currentDate = null;
do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
}
refreshIFrame();
sleep(1000);
</script>
</html>
不确定你想用这个来完成什么,但下面的方法会起作用。使用 setInterval 进行计时。我添加了缓存破坏器以备不时之需。
<iframe src="https://flowlab.io/game/play/1987226" style="width:1000px;height:600px;" id="HI"></iframe>
<script>
function refreshIFrame() {
console.log('Refresh');
var x = document.getElementById("HI");
//to help prevent cached reload, add a cache buster
const cb = new Date().getTime();
x.contentWindow.location.href = "https://flowlab.io/game/play/1987226?cb=" + cb;
}
setInterval(function() {
refreshIFrame();
}, 1000)
</script>