在PhoneGap应用,或者黑莓Java/HTML混搭应用中,如何使用JavaScript检查Mobile App网络连接状态呢?
- <script type="text/javascript">
- if (navigator.onLine) {
- alert("online");
- } else {
- alert("offline");
- }
- </script>
<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>
<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>
<script type="text/javascript"> if (navigator.onLine) { } else { $("#home_network_button").text('No Internet Access') .attr("data-icon", "delete") .button('refresh'); } </script> </div>
参考:
http://mobile.tutsplus.com/tutorials/phonegap/build-an-exercise-tracking-app-geolocation-tracking/