如何使用javascript检测移动连接是2G / 3G / WIFI [英] how to detect the mobile connection is 2G/3G/WIFI using javascript

查看:99
本文介绍了如何使用javascript检测移动连接是2G / 3G / WIFI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似于以下链接的要求,但我必须使用JavaScript来处理它。我必须检测移动互联网连接是2g / 3g还是WIFI。基于连接,我必须执行不同的操作..
注意:移动可以像任何操作系统一样,如andriod / iOS / BB ..我需要处理任何移动操作系统。

i have a similar requirement as in link below but i have to handle it by using JavaScript. where i have to detect whether the mobile internet connection is 2g/3g or it is WIFI . based on connection i have to perform diffent operations.. note : mobile can b of any OS like andriod/ iOS/BB .. i need to handle any mobile OS.

有没有办法检测我正在使用哪种连接? WiFi,3G或以太网?

请求主人帮我输入。谢谢:))

request masters to help me with inputs. thanks :)

推荐答案

网络信息API (这是一项实验性技术):

Network Information API (This is an experimental technology):


网络Information API提供有关系统的
连接的信息,该连接是根据一般连接类型(例如,'wifi',
'蜂窝'等)。这可用于根据用户的连接选择高清内容
或低清内容。整个
API包括添加domxref(NetworkInformation)
接口和一个属性到Navigator接口:
Navigator.connection。

The Network Information API provides information about the system's connection, which is in term of general connection type (e.g., 'wifi', 'cellular', etc.). This can be used to select high definition content or low definition content based on the user's connection. The entire API consists of the addition of the domxref("NetworkInformation") interface and a single property to the Navigator interface: Navigator.connection.



var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
var type = connection.type;

function updateConnectionStatus() {
  alert("Connection type is change from " + type + " to " + connection.type);
}

connection.addEventListener('typechange', updateConnectionStatus);

这篇关于如何使用javascript检测移动连接是2G / 3G / WIFI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆