NetworkInformation

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

备注: 此特性在 Web Worker 中可用。

网络信息 APINetworkInformation 接口提供有关设备正在使用的与网络进行通信的连接的信息,并提供了在连接类型发生变化时通知脚本的方法。NetworkInformation 接口不能被实例化,而需要通过 Navigator 接口或 WorkerNavigator 接口的 connection 属性进行访问。

EventTarget NetworkInformation

实例属性

此接口也从其父接口 EventTarget 继承属性。

返回以兆比特每秒为单位的有效带宽估计,四舍五入到最接近的 25 千比特每秒的倍数。

NetworkInformation.downlinkMax 只读

返回底层连接技术的最大下行速度,以兆比特每秒(Mbps)为单位。

NetworkInformation.effectiveType 只读

返回连接的有效类型(意思是“slow-2g”、“2g”、“3g”或“4g”中的一个)。此值是使用最近观察到的往返时间和下行链路值的组合来确定的。

NetworkInformation.rtt 只读

返回当前连接的有效往返时间估计,四舍五入到最接近的 25 毫秒的倍数。

NetworkInformation.saveData 只读

如果用户在用户代理上设置了减少数据使用的选项,则返回 true

NetworkInformation.type 只读

返回设备用于网络通信的连接类型。它会是以下值之一:

  • bluetooth
  • cellular
  • ethernet
  • none
  • wifi
  • wimax
  • other
  • unknown

实例方法

此接口也从其父接口 EventTarget 继承方法。

事件

change

在连接信息发生变化时触发的事件。

规范

Specification
Network Information API
# networkinformation-interface

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
NetworkInformation
change event
downlink
downlinkMax
Experimental
effectiveType
rtt
saveData
type
Experimental
typechange event
DeprecatedNon-standard
Available in workers

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
Non-standard. Check cross-browser support before using.
Deprecated. Not for use in new websites.
See implementation notes.

参见