document.getElementById('startTestButton').addEventListener('click', startSpeedTest);function startSpeedTest() { document.getElementById('loading').classList.remove('hidden'); document.getElementById('startTestButton').disabled = true;let image = new Image(); let startTime, endTime;image.onload = function() { endTime = (new Date()).getTime(); showResults(startTime, endTime); };startTime = (new Date()).getTime(); let downloadUrl = "https://www.example.com/somefile.jpg"; // replace with an actual large file URL image.src = downloadUrl + "?nn=" + Math.random();setTimeout(() => { // Fallback if the image doesn't load showResults(startTime, (new Date()).getTime()); }, 5000); // Timeout after 5 seconds }function showResults(startTime, endTime) { let duration = (endTime - startTime) / 1000; // seconds let bitsLoaded = 5000000; // Assuming a 5MB file let speedBps = (bitsLoaded / duration); // bits per second let speedMbps = (speedBps / 1024 / 1024); // convert to Mbpsdocument.getElementById('loading').classList.add('hidden'); document.getElementById('result').classList.remove('hidden'); document.getElementById('downloadSpeed').innerText = speedMbps.toFixed(2); }
×

Start a Conversation!

Hi! Click one of our members below to chat on WhatsApp

× Need Help? Chat with us