我需要提醒用户以下条件:
I need to alert the user with the following conditions;
如何在发生时捕获以下条件并提醒用户?
Here's the code; How to capture the following conditions when occurred and alert the user ?
failure: function (response) { var text = response.responseText; console.log("FAILED"); },success: function (response) { var text = response.responseText; console.log("SUCCESS"); }我试过下面的代码来检查互联网是否可达, 't work
I tried the following code to check if the internet is reachable, but it didn't work
var networkState = navigatorwork.connection.type alert(states[networkState]); if (networkState == Connection.NONE){ alert('No internet '); };UPDATE **
我在我的index.html添加了以下内容,但是,当我禁用WIFI,我没有看到警报弹出。
I added the following in my index.html, but, when i disable WIFI, i don't see the alert popping.
<script> function onDeviceReady() { document.addEventListener("offline", function() { alert("No internet connection"); }, false); } </script>推荐答案
最好的做法是听 离线事件。
The best thing to do is to listen to the "offline" event. When you get the offline event you can warn your user and take whatever steps necessary to save data, etc.
例如,您的deviceready回调:
For instance, your "deviceready" callback:
document.addEventListener("offline", function() { alert("No internet connection"); }, false);此代码应适用于大多数所有版本的PhoneGap。至少从1.0版本开始。
This code should work for most all versions of PhoneGap. It's been in since at least the 1.0 release.
更多推荐
如何在没有互联网连接时提醒用户
发布评论