这可能是一个菜鸟问题。我需要一个脚本来重定向到URL并每隔5分钟刷新一次该URL。
我开始:
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<script>
function init()
{
window.location.href = "my URL";
}
</script>
</head>
<body onload="init()">
</body>
</html>
它将打开我的URL,但如果我尝试在元标记中刷新,它不起作用,我需要刷新重定向的URL。
您无法为外国网站执行JavaScript代码。想象一下安全隐患。 (有关详细信息,请参阅此内容:How to access another tab in Chrome in javascript?)
可能是您的解决方案是每5分钟打开一个链接并关闭上一个链接。这将以间隔完成。但要小心,间隔永远不会停止......
var myWindow; // create global empty object
function openWindow(){
myWindow = window.open("www.google.de"); // define the opened window in there
}
openWindow(); //actually open the new window
setInterval(function(){
myWindow.close(); // close the specific window
openWindow() // open the window again
},30000) // executed every 5 minutes (30000 ms)
我真的不知道你需要什么,但我认为这是:
<script>
function init() {
var newWindow = window.open("http://mylink","_self");
//use _blank if you want it on a new tab
}
</script>
<script>
function reloadInterval() {
location.reload();
setTimeout(function(){
reloadInterval()
}, 300000)
}
function _interval() {
reloadInterval()
}
</script>
<img src="nosrc" alt="" onerror="reloadInterval()">
而不是使用onload使用:
<img src="onload-purposes" alt="" onerror="init()">
如果您还有其他需要,请评论此问题