Created
November 18, 2013 10:28
-
-
Save stefano-bortolotti/7525694 to your computer and use it in GitHub Desktop.
[JS] Determine connection type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
navigator.connection is supported on: android 2.2+, Chrome 30+ | |
*/ | |
var connection = navigator.connection || {'type':'0'}, // create a custom object if navigator.connection isn't available | |
connectionSpeed; | |
// determine connection speed | |
switch(connection.type) { | |
case connection.CELL_3G: // 3G | |
connectionSpeed = 'fast'; | |
break; | |
case connection.CELL_2G: // 2G | |
connectionSpeed = 'slow'; | |
break; | |
default: // WIFI, ETHERNET, UNKNOWN | |
connectionSpeed = 'fast'; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment