万象更新 Html5 - h5: h5 网络状态
万象更新 Html5 - h5: h5 网络状态
示例如下:
h5\mobile\networkStatus.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>网络状态</title>
</head>
<body>
<div id="txtMsg"></div>
<script>
var txtMsg = document.getElementById("txtMsg");
// navigator.onLine - 是否有网
txtMsg.innerHTML += "navigator.onLine: " + navigator.onLine;
txtMsg.innerHTML += "<br />";
// navigator.connection.type - 当前网络类型(测试了一下,android chrome 支持,ios safari 不支持)
// 可能的值有:cellular, wifi, ethernet, bluetooth, wimax, mixed, other, unknown, none
txtMsg.innerHTML += "navigator.connection.type: " + navigator.connection.type;
</script>
</body>
</html>