Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. Current Location: <BR>
  2. <button onclick="getLocation()">Locate</button>
  3. <p id="demo">
  4. Latitude: <input type="text" id="lat">
  5. Longitude: <input type="text" id="lon">
  6. </p>
  7. <script>
  8. function getLocation() {
  9. if (navigator.geolocation) {
  10. navigator.geolocation.getCurrentPosition(showPosition);
  11. } else {
  12. x.innerHTML = "Geolocation is not supported by this browser.";
  13. }
  14. }
  15.  
  16. function showPosition(position) {
  17. document.getElementById("lat").value = position.coords.latitude;
  18. document.getElementById("lon").value = position.coords.longitude;
  19.  
  20. }
  21. </script>
  22.  
  23. Current Wifi Speed: <BR>
  24. <button onclick="calculateWifiSpeed()">Calculate</button>
  25. <p id="demo">
  26. Wifi Speed: <input type="text" id="wifiSpeed">
  27. </p>
  28. <script>
  29. calculateWifiSpeed(){
  30. var imageAddr = "http://www.kenrockwell.com/contax/images/g2/examples/31120037-5mb.jpg";
  31. var downloadSize = 4995374; //bytes
  32.  
  33. window.onload = function() {
  34. var oProgress = document.getElementById("progress");
  35. oProgress.innerHTML = "Loading the image, please wait...";
  36. window.setTimeout(MeasureConnectionSpeed, 1);
  37. };
  38.  
  39. function MeasureConnectionSpeed() {
  40. var oProgress = document.getElementById("progress");
  41. var startTime, endTime;
  42. var download = new Image();
  43. download.onload = function () {
  44. endTime = (new Date()).getTime();
  45. showResults();
  46. }
  47.  
  48. download.onerror = function (err, msg) {
  49. oProgress.innerHTML = "Invalid image, or error downloading";
  50. }
  51.  
  52. startTime = (new Date()).getTime();
  53. var cacheBuster = "?nnn=" + startTime;
  54. download.src = imageAddr + cacheBuster;
  55.  
  56. function showResults() {
  57. var duration = (endTime - startTime) / 1000;
  58. var bitsLoaded = downloadSize * 8;
  59. var speedMbps = (speedKbps / 1024).toFixed(2);
  60. document.getElementById("wifiSpeed").value = speedMbps;
  61. oProgress.innerHTML = "Your connection speed is: <br />" + speedMbps + " Mbps<br />";
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement