[英]How can I use onoffline and ononline events in Chrome and other modern browsers?
I see that ononline
and onoffline
events are only available on Firefox and IE , but not for the other browsers (Chrome, Opera, Safari). 我看到
ononline
和onoffline
事件仅在Firefox和IE上可用 ,而其他浏览器(Chrome,Opera,Safari)不可用。 How could I set the events in Chrome and other modern browsers? 如何在Chrome和其他现代浏览器中设置事件?
Use navigator.onLine for all browser support as it is mentioned in link you provided. 将navigator.onLine用于所有浏览器支持,如您提供的链接中所述。 To whomever said that question is about checking if user is online - that's php's or what ever you prefer to use part not JS's.
不管怎么说,这个问题是关于检查用户是否在线的-这是php,或者您更喜欢使用部分而不是JS。
According to Bas van Dijk, I make it closer to perfection. 根据Bas van Dijk的说法,我使其更加接近完美。
function setOnOffline(onOnline=function (){},onOffline=function (){}){
window.online=onOnline;
window.offline=onOffline;
window.last123=navigator.onLine;registered
setInterval(function (){
if (!(window.last123==navigator.onLine)){
if (navigator.onLine){
window.online();
}else{
window.offline();
}
window.last123=navigator.onLine;
}
},1000/60);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.