gpt4 book ai didi

cordova - navigator.onLine 在我的手机上不起作用。如何检查互联网是否在线。离线???在Phonegap

转载 作者:行者123 更新时间:2023-12-04 19:06:50 25 4
gpt4 key购买 nike

我正在为我的应用程序使用 phonegap。我的应用程序基本上是来自一个网站的 RSS_FEED。
但我的要求是当没有互联网时,应用程序应该 alert - offline .

当应用程序在线运行时,所有数据都存储到数据库中。
当没有互联网时,从数据库获取数据的时间,所以我的问题只是应用程序每次在使用 navigator.onLine 时都显示我在线.

if(navigator.onLine) {
alert("check online");
loadScript("http://www.google.com/jsapi",msgOnFn)
loadScript("js/googleapi.js", msgOnFn);
} else {
loadScript("js/db.js",msgOffFn);
}

我试过 THIS ALSO
其中显示 wifi 每次。我不明白为什么会发生这种情况。

在网络浏览器中,它工作正常。 :)

最佳答案

请关注 phonegap documentation .

您还可以更改给定的函数以返回 true 或 false:

function checkConnection() {
var networkState = navigator.connection.type;

var states = {};
states[Connection.UNKNOWN] = false;
states[Connection.ETHERNET] = true;
states[Connection.WIFI] = true;
states[Connection.CELL_2G] = true;
states[Connection.CELL_3G] = true;
states[Connection.CELL_4G] = true;
states[Connection.CELL] = true;
states[Connection.NONE] = false;
if (states[networkState]) {
return true;
} else {
return false;
}
}

关于cordova - navigator.onLine 在我的手机上不起作用。如何检查互联网是否在线。离线???在Phonegap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22448591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com