属性:
connection.type
常量:
connection.UNKNOWN
connection.ETHERNET
connection.WIFI
connection.CELL_2G
connection.CELL_3G
connection.CELL_4G
connection.NONE
connection.type
检查正在使用的活动网络连接。
说明:
该属性是确定设备网络连接状态和连接类型的快速方法。
支持的平台:
iOS
Android
BlackBerry WebWorks (OS 5.0或更高版本)
简单的范例:
复制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();
1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.
完整的范例:
复制<!DOCTYPE html>
<html>
<head>
<title>navigator.network.connection.type Example</title>
<scripttype="text/javascript"charset="utf-8"src="phonegap.js"></script>
<scripttype="text/javascript"charset="utf-8">
// 等待加载PhoneGap
document.addEventListener(“deviceready“, onDeviceReady, false);
// PhoneGap加载完毕,可以安全调用PhoneGap方法
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>
<p>A dialog box will report the network state.</p>
</body>
</html>
1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~