example1.html 1.1 KB

1234567891011121314151617181920212223242526272829
  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. <div id="ip"></div>
  10. <h4>Download</h4>
  11. <div id="download"></div>
  12. <h4>Upload</h4>
  13. <div id="upload"></div>
  14. <h4>Latency</h4>
  15. <div id="ping"></div>
  16. <script type="text/javascript">
  17. var w=new Worker("speedtest_worker.min.js"); //create new worker
  18. setInterval(function(){w.postMessage("status");}.bind(this),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").innerHTML=data[1]+" Mbit/s";
  22. document.getElementById("upload").innerHTML=data[2]+" Mbit/s";
  23. document.getElementById("ping").innerHTML=data[3]+" ms, "+data[5]+" ms jitter";
  24. document.getElementById("ip").innerHTML=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>