[英]After click on button prevent reloading the page
So, my page automatically reloads after 20 seconds:所以,我的页面会在 20 秒后自动重新加载:
window.setInterval('refresh()', 20000);
function refresh() {
window.location.reload();
}
So I've added a button and contidion, if its true, page will reload.所以我添加了一个按钮和条件,如果它是真的,页面将重新加载。
if(siteRefreshButton === true){
window.setInterval('refresh()', 20000);
function refresh() {
window.location.reload();
}
function siteRefresh(){
siteRefreshButton = !siteRefreshButton;
console.log(siteRefreshButton);
}
My guess is, that after refresh, another interval starts before it can check if siteRefreshButton is true or false.我的猜测是,在刷新之后,另一个间隔开始,然后它可以检查 siteRefreshButton 是真还是假。 Any idea how can I make it work?
知道如何让它工作吗?
You could check your condition inside the refresh
function.您可以在
refresh
function 中检查您的情况。
var siteRefreshButton = true
function refresh() {
if (siteRefreshButton) {
window.location.reload()
}
}
function siteRefresh() {
siteRefreshButton = !siteRefreshButton
console.log(siteRefreshButton)
}
window.setInterval('refresh()', 20000)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.