html 5检查Mobile App是否在线

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

<script type="text/javascript">
  if (navigator.onLine) {
      alert("online");
  } else {
      alert("offline");
  }
</script>

jQuery Mobile中显示online/offline状态

<div data-role="content">
    <button id="home_network_button" data-icon="check">Internet Access Enabled</button>
  </div>

  <script type="text/javascript">
	 if (navigator.onLine) {  
	  } else {  
	    $("#home_network_button").text('No Internet Access')
	     .attr("data-icon", "delete")
	     .button('refresh');
	  }  
  </script>
</div>




参考:

navigator.onLine 离线检测 

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

你可能感兴趣的:(html,mobile,Access,NetWork,button,PhoneGap)