html 5检查Mobile App是否在线

在PhoneGap应用,或者黑莓Java/HTML混搭应用中,如何使用JavaScript检查Mobile App网络连接状态呢?

  1. <script type="text/javascript">
  2. if (navigator.onLine) {
  3. alert("online");
  4. } else {
  5. alert("offline");
  6. }
  7. </script>
<script type="text/javascript">
if (navigator.onLine) {
alert("online");
} else {
alert("offline");
}
</script>

jQuery Mobile中显示online/offline状态

  1. <div data-role="content">
  2. <button id="home_network_button" data-icon="check">Internet Access Enabled</button>
  3. </div>
<div data-role="content">
<button id="home_network_button" data-icon="check">Internet Access Enabled</button>
</div>
  1. <script type="text/javascript">
  2. if (navigator.onLine) {
  3. } else {
  4. $("#home_network_button").text('No Internet Access')
  5. .attr("data-icon", "delete")
  6. .button('refresh');
  7. }
  8. </script>
  9. </div>
  <script type="text/javascript">
if (navigator.onLine) {
} else {
$("#home_network_button").text('No Internet Access')
.attr("data-icon", "delete")
.button('refresh');
}
</script>
</div>

html 5检查Mobile App是否在线

参考:

navigator.onLine 离线检测

http://mobile.tutsplus.com/tutorials/phonegap/build-an-exercise-tracking-app-geolocation-tracking/

上一篇:git 使用详解(8)-- tag打标签


下一篇:1-3Controller之Response