"window.autoRefresh" 对于 safari 有什么选择?

What is the alternative of "window.autoRefresh" for safari?

在 safari 中 window.autoRefresh 不会被触发。如何使它起作用?而且我没有得到 window.autoRefresh 的任何示例和相同的文档。

此代码自动刷新 div 而不是页面

if(window.autoRefresh==true)//without this condition, refresh works fine.
        {
            if (typeof autoRefreshTimeout == 'undefined'){
            autoRefreshTimeout = setTimeout(function(){
                    clearTimeout(autoRefreshTimeout);
                    autoRefreshTimeout = undefined;
                    dosomething();
                    }

                }, 30000);
            }

没有属性window.autoRefresh。如果需要,您可以将其设置为自定义 属性。如果要在几毫秒后刷新多次,请使用 setInterval 而不是 setTimeout

var autoRefreshTimeout;
var count = 0;
    
// function that change div content
function dosomething() {
  document.getElementById('counter').innerHTML = count;
  count++;
}

// start timeout/interval
function startRefresh() {
  // check if already refreshing
  if(!window.autoRefresh) {
    // set custom property
    window.autoRefresh = true;

    // autoRefreshTimeout = setTimeout(function() {
    autoRefreshTimeout = setInterval(function() {
      console.log('refresh');
      dosomething();
    }, 1000);
  }
}

// stop timeout/interval
function stopRefresh() {
  if (window.autoRefresh) {
    // set custom property
    window.autoRefresh = false;

    // clearTimeout(autoRefreshTimeout);
    clearInterval(autoRefreshTimeout);
  }
}
<button onclick='startRefresh()'>start</button>
<button onclick='stopRefresh()'>stop</button>
<div id="counter"></div>