使用phonegap检测网络状态的方法
程序员文章站
2023-12-14 22:48:58
下面小编就为大家带来一篇使用phonegap检测网络状态的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧... 17-03-30...
实例如下:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>check network</title> <script type="text/javascript" charset="utf-8" src="cordova.js"></script> <script type="text/javascript" charset="utf-8"> document.addeventlistener("deviceready", ondeviceready, false); function ondeviceready() { checkconnection(); } //关键代码 function checkconnection(){ var networkstate=navigator.network.connection.type; var states={}; states[connection.unknown]='unknown connection'; states[connection.ethernet]='ethernet connection'; states[connection.wifi]='wifi connection'; states[connection.cell_2g]='cell 2g connection'; states[connection.cell_3g]='cell 3g connection'; states[connection.cell_4g]='cell 4g connection'; states[connection.none]='no network connection'; alert('connection type: '+states[networkstate]); } </script> </head> <body onload="onload()"> <p id="props"> a dialog box will report the network state.</p> </body> </html>
以上这篇使用phonegap检测网络状态的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。