我正在使用网络信息API获取网络类型。
var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
// output in Microsoft edge browser console
// {onchange: null, effectiveType: "4g", rtt: 100, downlink: 1.5, saveData: false}我在使用公司的无线网络。我希望effectiveType属性的值应该是wifi。因为我有这样的代码逻辑:
if(effectiveType === 'wifi') {
// Do something
} else if (effectiveType === '4g') {
// Do other things
}这有可能吗?我找到了NetworkInformation.type的只读属性,但它给了我undefined。它不支持边缘。
我看到EffectiveConnectionType enum没有wifi值。
环境:
发布于 2021-10-01 13:54:02
如果您查看W3C上的API规范,wifi不是“有效的连接类型”之一。EffectiveConnectionType枚举使用4g作为快速可靠连接的最高名称。
type属性在navigator.connection上使用枚举作为其值,因此wifi是其可能的值之一。但是,API接口,所以Edge总是说type是undefined。
如果您在生产中使用基于这种技术的特性,我会倾向于使用effectiveType,但NetworkInformation API仍然是一种实验性技术,即非官方草案和不支持跨浏览器。
https://stackoverflow.com/questions/66899110
复制相似问题