PhoneGap中文网
标题:
PhoneGap Connection 确定设备网络连接状态api
[打印本页]
作者:
admin
时间:
2013-6-20 21:38
标题:
PhoneGap Connection 确定设备网络连接状态api
说明:
该属性是确定设备网络连接状态和连接类型的快速方法。
支持的平台:
iOS
Android
BlackBerry WebWorks (OS 5.0或更高版本)
Windows Phone 7 ( Mango )
简单的范例:
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]);
}
checkConnection();
复制代码
完整的范例:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>PhoneGap-NetWork</title>
<link rel="stylesheet" href="../jquery.mobile-1.1.1/jquery.mobile-1.1.1.css" />
<script src="../jquery.mobile-1.1.1/jquery.js"></script>
<script src="../jquery.mobile-1.1.1/jquery.mobile-1.1.1.js"></script>
<script type="text/javascript" charset="utf-8" src="../cordova-1.9.0.js"></script>
<script type="text/javascript">
$(document).ready(function(){
document.addEventListener("deviceready", myDeviceReadyListener, false);
});
function myDeviceReadyListener(){
var networkState = navigator.network.connection.type;
var states = {};
states[Connection.UNKNOWN]= "未知网络";
states[Connection.ETHERNET]= "蓝牙网络";
states[Connection.WIFI]= "WIFI无线网络";
states[Connection.CELL_2G]= "2G网络";
states[Connection.CELL_3G]= "3G网络";
states[Connection.CELL_4G]= "4G网络";
states[Connection.NONE]= "无网络";
$("#networkState .ui-btn-text").text(states[networkState]);
}
</script>
</head>
<body>
<div data-role="page">
<div data-role="header">
<h1>PhoneGap实战</h1>
</div>
<div data-role="content">
<a href="#" data-role="button" id="networkState">网络获取中....</a>
</div>
<div data-role="footer">
<h4> </h4>
</div>
</div>
</body>
</html>
复制代码
作者:
app
时间:
2013-11-12 18:14
请问如何 获取当前设备的Ip
作者:
admin
时间:
2013-11-16 09:44
app 发表于 2013-11-12 18:14
请问如何 获取当前设备的Ip
ip官网没有给提供接口 得自己写插件
欢迎光临 PhoneGap中文网 (http://bbs.phonegap100.com/)
Powered by Discuz! X3.2