navigator.onLine不工作科尔多瓦5.0.0 [英] navigator.onLine not working cordova 5.0.0

查看:200
本文介绍了navigator.onLine不工作科尔多瓦5.0.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题,检查设备是否具有没有互联网连接。我使用的科尔多瓦5.0.0 CLI。这是我的code:

I am having problems with checking if a device has no internet connection. I am using cordova 5.0.0 CLI. This is my code:

if(navigator.onLine) {
  alert("online");
} else {
  alert("offline");
  window.open("404.html");
}

现在的问题是:它总是如此。我该如何解决呢?我知道这插件,但我不知道我怎么连都搞不定。我知道如何添加插件,但它结束。可能有人帮助我获得这个插件的工作,或替代code,以检查用户是否处于脱机状态?在此先感谢

The problem is: it's always true. How can i fix it? I know this plugin, but I don't know how I even get it working. I know how to add plugins, but then it ends. Could someone help me getting this plugin working, or an alternative code to check if a user is offline? Thanks in advance

推荐答案

添加到您的index.html:

Add this to your index.html :

document.addEventListener("offline", function(){ navigator.notification.alert("No connection found") }, false);

这会提醒你,如果没有网络连接。

It will alert you if there isn't a network connection.

如果您还没有通知插件:

If you don't have the notification plugin :

document.addEventListener("offline", function(){ alert("No connection found") }, false);

这篇关于navigator.onLine不工作科尔多瓦5.0.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆