如果在用网页端的话,以前常用的方法就是去轮询一个肯定存在的指定大小的文件,javascript计算下载完成的时间,然后计算出结果,但是现在浏览器有一个实验性的API,Network Information API(浏览器支持度要自己查一下)https://developer.mozilla.org...不过实时网速好像也不是很精确function logConnectionType() { let connectionType = 'not supported'; let downlinkMax = 'not supported'; let downlink = 'not supported' if ('connection' in navigator) { connectionType = navigator.connection.effectiveType; if ('downlinkMax' in navigator.connection) { downlinkMax = navigator.connection.downlinkMax; } if ('downlink' in navigator.connection) { downlink = navigator.connection.downlink } } console.log(`Current connection type: ${connectionType} (downlink max: ${downlinkMax} Mb/s) (downlink: ${downlink} Mb/s)`); } logConnectionType(); navigator.connection.addEventListener('change', logConnectionType);你可以在手机上试试,手机上donlinkMax可以被支持
如果在用网页端的话,以前常用的方法就是去轮询一个肯定存在的指定大小的文件,javascript计算下载完成的时间,然后计算出结果,
但是现在浏览器有一个实验性的API,Network Information API(浏览器支持度要自己查一下)
https://developer.mozilla.org...
不过实时网速好像也不是很精确
你可以在手机上试试,手机上donlinkMax可以被支持
