我有一个网页,并且有一个刷新按钮。我需要每5分钟点击一次按钮。 “正常刷新”或“重新加载”或F5在这种情况下不起作用。 Javascript是否可以执行此任务?
就像,我将JavaScript保存为“书签”,然后单击书签。然后,javascript事件必须每5分钟点击刷新按钮。
我用Google搜索它,发现下面的代码。但是,它不起作用。当我单击它时,它只是在空白页中显示一个随机数。
javascript:if(window.autoRefreshInterval) { clearInterval(window.autoRefreshInterval); };
window.autoRefreshInterval = setInterval(function() { jQuery(".refresh").click(); },60000)
先谢谢您,
答案 0 :(得分:1)
“我有一个网页,并且有一个刷新按钮。我需要单击 每5分钟按一次。正常刷新或重新加载或F5不 在这种情况下工作。有没有办法Javascript可以做到这一点 任务。”
我不太清楚,但是每次刷新网页时,都会重新加载javascript。因此,如果您有间隔或变量,则它们将在每次刷新时重置。如果要在刷新之间保留一些值,则可以使用localStorage或cookie存储值。 如果要自动刷新页面,可以使用setInterval或metatag "refresh"。
”“就像,我将javascript保存为书签,然后单击 书签。然后,javascript事件必须单击刷新按钮 每5分钟。”
答案 1 :(得分:0)
您可以在
中调用刷新代码功能或按钮单击事件setTimeout(yourFucntion(),5000);
else
setTimeout($("#btnName").click(),5000);
答案 2 :(得分:0)
您可以尝试使用两种版本,一种使用javascript单击按钮,另一种自动运行与该按钮绑定的功能。
非jQuery:
javascript:(function(){if(window.autoRefreshInterval) {clearInterval(window.autoRefreshInterval);}window.autoRefreshInterval = setInterval(function(){document.getElementsByClassName("refresh")[0].addEventListener('click');},60000);})()
或者使用jQuery(OP对原始线程的注释):
javascript:(function(){if(window.autoRefreshInterval) {clearInterval(window.autoRefreshInterval);}window.autoRefreshInterval = setInterval(function(){$ctrl.refresh();},60000);})()
答案 3 :(得分:0)
尝试以下代码:
<!DOCTYPE html>
<html>
<body onload="f1()">
<script language ="javascript" >
var tmp;
function f1() {
tmp = setInterval(() => f2(), 2000); // replace this with 5 min timer
}
function f2() {
document.getElementById("Button1").click();
}
function f3() {
console.log("Hello World");
}
</script>
<button id="Button1" onclick="f3()">click me</button>
<div id="demo"></div>
</body>
</html>
答案 4 :(得分:0)
延迟发布,但希望它可以帮助某人:-)。
我的诀窍是通过 css document.querySelector('.pbi-glyph-refresh').click();
您可以像这样将其与原始代码结合起来,它会正确单击 60 秒计时器上的 PowerBI 刷新按钮(var 以毫秒为单位)。
javascript:if(window.autoRefreshInterval) { clearInterval(window.autoRefreshInterval); };
window.autoRefreshInterval = setInterval(function() {document.querySelector('.pbi-glyph-refresh').click(); },60000)