0

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

Could someone please look into this?

halfer
  • 19,824
  • 17
  • 99
  • 186
Kuldeep Singh
  • 29
  • 1
  • 1
  • 5
  • 4
    http://stackoverflow.com/questions/5529718/how-to-detect-internet-speed-in-javascript – Paul Fitzgerald May 26 '15 at 11:09
  • What have you tried? You can simply check the time between the start and response of an Ajax request, but that is the response speed of that server. – iCollect.it Ltd May 26 '15 at 11:09
  • @ Paul: refered code is working but i dont thik it's resulting to required aspect, when i am hitting this code with one image at localhost, its giving different result every time like this::::Your connection speed is: 4234.63 Mbps, Your connection speed is: 1022.63 Mbps, Your connection speed is: 5005.64 Mbps – Kuldeep Singh May 26 '15 at 11:45
  • Hey Paul: can you please help me out to understand why this is giving that much speed which is not correct? Thanks for you time, buddy ! :) – Kuldeep Singh May 26 '15 at 12:05
  • its a bit urgent if somebody can help me out here, that will be great, please help me out to understand, speed is too bigger like 100 mbps, 150 mbps but i actually tried online that actual downloading speed is 2.5 ro 3 mbps. – Kuldeep Singh May 26 '15 at 12:28
  • This is too brief for questions here, voting to delete. – halfer Oct 11 '15 at 14:45

1 Answers1

2

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;
}
Clément Béligat
  • 63
  • 1
  • 2
  • 12
  • connection.bandwidth is javascript property or do i need to add something to get this working. – Kuldeep Singh May 26 '15 at 11:18
  • i have tried this code but its not working, connection is being fired at undefined. var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection; alert("connection="+navigator.connection); // Check for browser support if (!!connection) { // Get the connection type var type = connection.type; alert("type="+type); // Get the connection speed in megabits per second (Mbps) var speed = connection.downlinkMax || connection.bandwidth; alert("speed="+speed); } – Kuldeep Singh May 26 '15 at 11:50
  • 2
    https://developer.mozilla.org/en/docs/Web/API/NetworkInformation/connection#Browser_compatibility – A. Wolff May 26 '15 at 11:52
  • I have referred the link, but that is not supported with all browsers.. – Kuldeep Singh May 26 '15 at 12:04
  • `downlinkMax` is indeed in megabits per second, but `bandwidth` is in megabytes per second. Then again, `bandwidth` was never supported by any stable browser, and `downlinkMax` is not supported yet by any stable browser... – Tgr May 28 '15 at 12:14
  • Currently the only major browser that supports this is [Chrome on Android](http://caniuse.com/#feat=netinfo). For now it's probably better to use the method outlined [here](http://stackoverflow.com/questions/5529718/how-to-detect-internet-speed-in-javascript). – Husky Apr 07 '16 at 13:53
  • On newest version on chrome, connection is undefined – Festim Cahani Jun 10 '16 at 14:27