example1.html 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Speedtest</title>
  5. </head>
  6. <body>
  7. <h1>Speedtest</h1>
  8. <h4>IP Address</h4>
  9. <p id="ip"></p>
  10. <h4>Download</h4>
  11. <p id="download"></p>
  12. <h4>Upload</h4>
  13. <p id="upload"></p>
  14. <h4>Latency</h4>
  15. <p id="ping"></p>
  16. <script type="text/javascript">
  17. var w = new Worker('speedtest_worker.min.js') // create new worker
  18. setInterval(function () { w.postMessage('status') }, 100) // ask for status every 100ms
  19. w.onmessage = function (event) { // when status is received, split the string and put the values in the appropriate fields
  20. var data = event.data.split(';') // string format: status;download;upload;ping (speeds are in mbit/s) (status: 0=not started, 1=downloading, 2=uploading, 3=ping, 4=done, 5=aborted)
  21. document.getElementById('download').textContent = data[1] + ' Mbit/s'
  22. document.getElementById('upload').textContent = data[2] + ' Mbit/s'
  23. document.getElementById('ping').textContent = data[3] + ' ms, ' + data[5] + ' ms jitter'
  24. document.getElementById('ip').textContent = data[4]
  25. }
  26. w.postMessage('start') // start the speedtest (default params. keep garbage.php and empty.dat in the same directory as the js file)
  27. </script>
  28. </body>
  29. </html>