Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Current Location: <BR>
- <button onclick="getLocation()">Locate</button>
- <p id="demo">
- Latitude: <input type="text" id="lat">
- Longitude: <input type="text" id="lon">
- </p>
- <script>
- function getLocation() {
- if (navigator.geolocation) {
- navigator.geolocation.getCurrentPosition(showPosition);
- } else {
- x.innerHTML = "Geolocation is not supported by this browser.";
- }
- }
- function showPosition(position) {
- document.getElementById("lat").value = position.coords.latitude;
- document.getElementById("lon").value = position.coords.longitude;
- }
- </script>
- Current Wifi Speed: <BR>
- <button onclick="calculateWifiSpeed()">Calculate</button>
- <p id="demo">
- Wifi Speed: <input type="text" id="wifiSpeed">
- </p>
- <script>
- calculateWifiSpeed(){
- var imageAddr = "http://www.kenrockwell.com/contax/images/g2/examples/31120037-5mb.jpg";
- var downloadSize = 4995374; //bytes
- window.onload = function() {
- var oProgress = document.getElementById("progress");
- oProgress.innerHTML = "Loading the image, please wait...";
- window.setTimeout(MeasureConnectionSpeed, 1);
- };
- function MeasureConnectionSpeed() {
- var oProgress = document.getElementById("progress");
- var startTime, endTime;
- var download = new Image();
- download.onload = function () {
- endTime = (new Date()).getTime();
- showResults();
- }
- download.onerror = function (err, msg) {
- oProgress.innerHTML = "Invalid image, or error downloading";
- }
- startTime = (new Date()).getTime();
- var cacheBuster = "?nnn=" + startTime;
- download.src = imageAddr + cacheBuster;
- function showResults() {
- var duration = (endTime - startTime) / 1000;
- var bitsLoaded = downloadSize * 8;
- var speedMbps = (speedKbps / 1024).toFixed(2);
- document.getElementById("wifiSpeed").value = speedMbps;
- oProgress.innerHTML = "Your connection speed is: <br />" + speedMbps + " Mbps<br />";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement