简体   繁体   English

如何在Chrome和其他现代浏览器中使用离线事件和在线事件?

[英]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). 我看到ononlineonoffline事件仅在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.

相关问题 我可以在使用JavaScript的现代浏览器中使用或打开“插入”插入符号吗? - Can I use or turn on the 'insert' caret in modern browsers using javascript? 如何在现代浏览器中实现lodash _.remove函数? - How can I implement the lodash _.remove function in modern browsers? 如何在现代浏览器中使用mousein事件? - How do I use the mousein event in modern browsers? 如何在现代浏览器中全局监听获取完成? - How can I globally listen for fetch completion in modern browsers? 我们如何在现代Web浏览器中使用es6模块而不转换代码 - How can we use es6 modules in modern web browsers without transpiling the code 有没有办法在现代浏览器中用javascript替换这个lodash _.chain代码? - Is there a way I can replace this lodash _.chain code with javascript in modern browsers? 使用Javascript优化现代浏览器(Chrome)的计时器 - Optimising timers for modern browsers (Chrome) in Javascript Chrome mousedown和mouseup事件不再有效,其他浏览器也没问题 - Chrome mousedown and mouseup events no longer working, other browsers are fine 我无法在Google Chrome中读取Cookie,但可以在所有其他浏览器中读取 - I cant read my cookie out in google chrome but I can in all other browsers 如何向Chrome / Chromium浏览器添加一些内容? - How can I add some content to Chrome/Chromium browsers?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM