如何使用 JavaScript 和 jQuery 找出用户的互联网连接速度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30456815/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 12:12:35  来源:igfitidea点击:

How to find out the internet connection speed of user using JavaScript and jQuery?

javascriptjquery

提问by Kuldeep Singh

I need to find out the internet connection speed of user's PC using JavaScript or jquery.

我需要使用 JavaScript 或 jquery 找出用户 PC 的互联网连接速度。

Could someone please look into this?

有人可以看看这个吗?

回答by Clément Béligat

You can probably do that to estimated download bandwidth in megabytes per second of the current connection.

您可能可以这样做来估计当前连接每秒的下载带宽(以兆字节为单位)。

// Some browsers use prefixes so let's cope with them first
var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;

// Check for browser support
if (!!connection) {
  // Get the connection type
  var type = connection.type;

  // Get the connection speed in megabits per second (Mbps)
  var speed = connection.downlinkMax || connection.bandwidth;
}