example.html 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Speedtest</title>
  5. <script type="text/javascript" src="speedtest.js"></script>
  6. </head>
  7. <body>
  8. <h1>Speedtest</h1>
  9. <h4>Download</h4>
  10. <div id="download">Wait...</div>
  11. <h4>Upload</h4>
  12. <div id="upload">Wait...</div>
  13. <h4>Latency</h4>
  14. <div id="ping">Wait...</div>
  15. <script type="text/javascript">
  16. var tester=new DownloadTester("garbage.php",function(){
  17. //when the download test is done, start the upload test
  18. tester=new UploadTester("upload-test", function(){
  19. //when the upload test is done, start the latency test
  20. tester=new PingTester("empty.dat",null //when the test ends, do nothing
  21. ,function(){
  22. //called periodically to update latency
  23. document.getElementById("ping").innerHTML=tester.getValue()+" ms";
  24. },function(){
  25. //when the latency test fails
  26. document.getElementById("ping").innerHTML="Failed";
  27. }
  28. );
  29. },function(){
  30. //called periodically to update upload speed
  31. document.getElementById("upload").innerHTML=tester.getValue()+" Megabit/s";
  32. },function(){
  33. //when the upload test fails
  34. document.getElementById("upload").innerHTML="Failed";
  35. tester.onDone();
  36. });
  37. },function(){
  38. //called periodically to update download speed
  39. document.getElementById("download").innerHTML=tester.getValue()+" Megabit/s";
  40. },function(){
  41. //when the download test fails
  42. document.getElementById("download").innerHTML="Failed";
  43. tester.onDone();
  44. });
  45. </script>
  46. </body>
  47. </html>