2016-07-14 6 views
1

실제로 일부 업데이트가 데이터베이스에서 발생하면 알림 사운드가 재생되므로 브라우저가 최소화 된 상태에서 5 초마다 페이지를 새로 고치려고합니다.하지만 Firefox에서는 제대로 작동하지만 Chrome에서는 문제가 없습니다. 이 작동하지 않습니다.브라우저가 최소화 될 때 매 5 초마다 javascript 다시로드 페이지

시나리오 :

브라우저를 최소화하고 컴퓨터의 유휴 둡니다.

나는 두 가지 방법을 시도 :

방법 1 :

<meta http-equiv="refresh" content="5;URL=http://example.com/" /> 

방법 2 :

<script> 

    $(document).ready(function() { 

    setTimeout(function(){ 
    window.location.reload(1); 
    }, 5000); 

    }); 

</script> 

어떤 도움이 좋을 것.

+0

클라이언트 자바 스크립트에서 브라우저 창이 최소화되어 있는지 확인할 수 없습니다. – VisioN

+0

@Vision, 브라우저 창을 최소화 한 경우에도 Firefox에서 자동 다시로드가 작동하지만 Chrome이 아닌 이유는 무엇입니까? – stom

+0

서버에서 업데이트 된 데이터 자체를 가져올 수있을 때 전체 페이지를 다시로드하는 이유는 무엇입니까? 어쨌든'window.location.href = window.location.href; – KRONWALLED

답변

1

흐림초점 윈도우의 뷰 상태를 감지 할 수 이벤트.

예 :이 도움이

var timer = null; 

//when the window is minimized or when user is in different tab . 
    window.addEventListener('blur', function(){ 

     timer = setInterval(function(){ 

      window.location.reload(1); 

     },5000) 

    }, false); 


//when user is back to window 
    window.addEventListener('focus', function(){ 

     //stop the page reload once 

     if(timer != null){ 

     clearInterval(timer); 

     } 
    }, false); 

희망.

관련 문제