js判断手机连接网络类型

<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<title>Connection API</title>
</head>
<body>
<button id="btn" type="button">Get Ststus</button>
<div id="re" style="margin-top: 10px;"></div>
<script type="text/javascript">
var connection = navigator.connection||navigator.mozConnection||navigator.webkitConnection||{tyep:‘unknown‘};
var type_text = [‘unknown‘,‘ethernet‘,‘wifi‘,‘2g‘,‘3g‘,‘4g‘,‘none‘];

alert(connection.type);
var re_el = document.getElementById("re");
var btn_el = document.getElementById("btn");
function get_status(){
if(typeof(connection.type) == "number"){
connection.type_text = type_text[connection.type];
}else{
connection.type_text = connection.type;
}
if(typeof(connection.bandwidth) == "number"){
if(connection.bandwidth > 10){
connection.type = ‘wifi‘;
}else if(connection.bandwidth > 2){
connection.type = ‘3g‘;
}else if(connection.bandwidth > 0){
connection.type = ‘2g‘;
}else if(connection.bandwidth == 0){
connection.type = ‘none‘;
}else{
connection.type = ‘unknown‘;
}
}
var html = ‘Type : ‘+connection.type_text;
html += ‘<br>Bandwidth : ‘+connection.bandwidth;
html += ‘<br>isOnline : ‘+navigator.onLine;
re_el.innerHTML = html;
}

btn_el.onclick = function(){
re_el.innerHTML = ‘Waiting...‘;
get_status();
}

</script>
</body>
</html>

时间: 2024-08-08 11:56:14

js判断手机连接网络类型的相关文章

判断手机连接的是fdd还是tdd的办法

判断手机连接的是fdd还是tdd的办法http://bbs.ydss.cn/thread-550035-1-1.html移动4G一般都是tdd,联通则可能有tdd,还有可能是fdd,判断手机连接的是tdd还是fdd的办法:1.首先上网搜索谷歌安装器1.5,安装google服务框架,google商店,然后上网搜索安装google play服务,有很多版本,必须安装正确的版本,要求适用于安卓5.0,armv8架构,320dpi分辨率,这个是后面的测试软件必须要用到的. http://www.apkm

js判断手机浏览器操作系统和微信浏览器的方法

做手机端的前端开发,少不了对手机平台的判断.如,对于app下载,就要判断在Android平台下就显示Android下载提示:在iOS平台下就显示iOS下载提示. 今天就为大家介绍一下用js判断手机客户端平台及系统平台的方法: <script type="text/javascript"> //手机端判断各个平台浏览器及操作系统平台 function checkPlatform(){ if(/android/i.test(navigator.userAgent)){ docu

js判断手机浏览器

最新浏览器识别合并. demo:http://v.qq.com    ->   http://v.qq.com/h5 http://v.qq.com/    ->   http://v.qq.com/h5 http://v.qq.com/h5    ->   http://v.qq.com/h5 <script type="text/javascript"> (function(W){ if(!/\/h5/.test(W.location.pathname

Android判断用户的网络类型(2/3/4G、wifi)

很多时候需要先判断当前用户的网络,才会继续之后的一些处理逻辑.但网络类型获取这一块,我用我自己的的手机调试时遇到一些问题,这里记录一下. 一加手机一代,移动4G 网络,得到的subtype类型值为17,我查过Android 5.1的源码,它最大的值也就为16.(点击这里在线查看源码>>)   我拿魅族的移动4G测试的结果如下:   小米4,电信4G的测试结果如下: 魅族MX4,联通3G   还测试了其它华为移动3G/4G的情况,就我自己的手机一加返回的值有点奇怪,之后我查了一下它的参数:htt

[Javascript]js判断是否为undefined类型

概述 在项目获取某个元素的值会出现undefined,所以对这种情况要有特殊处理. 可通过下面的代码判断是否为undefined类型. 1 if (typeof(reValue) == "undefined") { 2 alert("undefined"); 3 } 4 5 typeof 返回的是字符串,有六种可能:"number"."string"."boolean"."object"

php js 判断手机访问

<?php function isMobile(){ $useragent=isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $useragent_commentsblock=preg_match('|\(.*?\)|',$useragent,$matches)>0?$matches[0]:''; function CheckSubstrs($substrs,$text){ foreach($subst

IOS判断用户的网络类型(2/3/4G、wifi)

直接贴代码吧,ios7之后是获取的较为准确,7以下我拿iphone5测试的是无法区分3g/2g.连iphone4都能升到7.1.4,而且目前主流的设备7以下的系统已经很少了,这个方案尽管不太完美,但影响不会太大   #import <CoreTelephony/CTTelephonyNetworkInfo.h> string GetNetWorkType(){    string strNetworkType = "";        //创建零地址,0.0.0.0的地址表

js判断手机浏览器是横屏or竖屏

移动端的浏览器一般都支持window.orientation这个参数,通过这个参数可以判断出手机是处在横屏还是竖屏状态. 从而根据实际需求而执行相应的程序.通过添加监听事件onorientationchange,进行执行就可以了. //判断手机横竖屏状态: function hengshuping(){ if(window.orientation==180||window.orientation==0){ alert("竖屏状态!") } if(window.orientation==

js判断手机是否安装了某一款app,有则打开,没有去下载

function openApp(){ if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) { var loadDateTime = new Date(); window.setTimeout(function() { var timeOutDateTime = new Date(); if(timeOutDateTime - loadDateTime < 5000) { window.location = "要跳转的下载app页面