1
0

worker.html 645 B

12345678910111213141516171819202122232425262728293031323334
  1. <!doctype html>
  2. <title>Worker</title>
  3. <script>
  4. "use strict";
  5. window.onload = function()
  6. {
  7. var worker = new Worker("worker.js");
  8. var terminal = document.getElementById("terminal");
  9. worker.onmessage = function(e)
  10. {
  11. terminal.textContent += e.data;
  12. }
  13. terminal.onkeypress = function(e)
  14. {
  15. e.preventDefault();
  16. worker.postMessage(String.fromCharCode(e.which));
  17. };
  18. }
  19. var start = Date.now();
  20. setInterval(function()
  21. {
  22. document.getElementById("time").textContent = (Date.now() - start) / 1000 | 0;
  23. });
  24. </script>
  25. <span id=time></span>s
  26. <hr>
  27. <textarea rows=25 cols=80 id=terminal></textarea>