2017-05-22 1 views
0

사파리에서 window.autoRefresh이 실행되지 않습니다. 어떻게 작동하게할까요? 그리고 저는 window.autoRefresh의 예제와 동일한 문서를 얻었습니다.safari에 대한 "window.autoRefresh"의 대안은 무엇입니까?

이 코드는 DIV하지 페이지 프로퍼티 window.autoRefresh이 없습니다

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

       }, 30000); 
      } 

답변

1

을 autofreshes. 원하는 경우 사용자 정의 속성으로 설정할 수 있습니다. 몇 밀리 초 후에 여러 번 새로 고치려면 setTimeout 대신 setInterval을 사용하십시오.

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>

관련 문제