admin管理员组文章数量:1435859
I am wondering if there is a way to disable an automatic page refresh when a page loses focus. I have it setup to refresh when it gains focus again already using this:
window.onblur= function() {window.onfocus= function () {location.reload(true)}};
that I found from here. I originally had the page auto refresh by using:
<meta http-equiv="refresh" content="60"/>
Which reloads the page every 60 seconds regardless of state.
I want to make the page have the auto refresh only when in focus with the initial refresh ing when the page gains focus again. After the gain of focus it should refresh at the time interval until focus is lost.
Thanks
I am wondering if there is a way to disable an automatic page refresh when a page loses focus. I have it setup to refresh when it gains focus again already using this:
window.onblur= function() {window.onfocus= function () {location.reload(true)}};
that I found from here. I originally had the page auto refresh by using:
<meta http-equiv="refresh" content="60"/>
Which reloads the page every 60 seconds regardless of state.
I want to make the page have the auto refresh only when in focus with the initial refresh ing when the page gains focus again. After the gain of focus it should refresh at the time interval until focus is lost.
Thanks
Share Improve this question edited May 23, 2017 at 11:44 CommunityBot 11 silver badge asked Jun 15, 2013 at 21:36 thekgb09thekgb09 778 bronze badges 1- You could try to use Page Visibility API – w3/TR/page-visibility – gearsdigital Commented Jun 15, 2013 at 22:29
2 Answers
Reset to default 5You can't override this kind of refresh, you should probably use a JS timer to refresh, something like this (after removing the <meta http-equiv="refresh" content="60" />
tag):
var hasFocus;
window.onblur = function() {
hasFocus = false;
}
window.onfocus = function(){
hasFocus = true;
}
setInterval(reload, 60*1000);
function reload(){
if(hasFocus){
location.reload(true);
}
}
I ended up modifying the code from Mostafa Torbjørn Berg to maintain the refresh on focus and have the page automatically refresh every 60 seconds while the page has focus.
var hasFocus= true;
window.onblur = function() {
hasFocus = false;
}
window.onfocus = function(){
location.reload(true);
}
setInterval(reload, 60*1000);
function reload(){
if(hasFocus){
location.reload(true);
}
}
本文标签: phpdisable page refresh on lose focusStack Overflow
版权声明:本文标题:php - disable page refresh on lose focus - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745666447a2669315.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论