前端js调用navigator Network Information API获取设备网络状态
发布日期:2022-03-30 20:19:28 浏览次数:23 分类:博客文章

本文共 669 字,大约阅读时间需要 2 分钟。

支持列表:(不支持IOS)

 

 需要使用:

var connection = navigator.connection;

获取object。

 

此object有以下属性:

  • downlink: 下行网络速度,M/s为单位
var downLink = navigator.connection.downlink;
  • rtt: 有效往返时间(延迟),ms为单位,四舍五入到25的倍数
var rtt = navigator.connection.rtt;
  • type: 获取网络类型
connectionType = navigator.connection.type//获得以下其中一个状态:// bluetooth: 蓝牙// cellular: 数据连接,如3g,4g// wifi// ethernet: 以太网// wimax: 微波// none: 没有连接网络// mixed: 多种网络连接// other: 已知的连接类型,但不是上述任何的连接类型之一// unknown: 用户代理已建立网络连接,但无法或不愿确定底层连接技术
  • effectiveType: 根据下载速度和延迟估计相对应的网络

例如:downloadlink = 0.5M/s,rtt = 200, effectiveType = 3g

var effectiveType = navigator.connection.effectiveType;

 

参考文档:https://wicg.github.io/netinfo/#downlinkmax-attribute

转载地址:https://www.cnblogs.com/aidenchen8/p/15116817.html 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:学习Python的好工具jupyter notebook
下一篇:Wamp2.5(Apache2.4.9)外网访问403(Forbidden)错误

发表评论

最新留言

关注你微信了!
[***.104.42.241]2024年04月12日 09时40分27秒