websocket_shared_worker.html 543 B

123456789101112131415161718192021222324
  1. <html>
  2. <body>
  3. <div id=result></div>
  4. <script>
  5. function log(message)
  6. {
  7. document.getElementById("result").innerHTML += message + "<br>";
  8. }
  9. var worker = new SharedWorker("websocket_worker_simple.js");
  10. var protocol = location.protocol.replace('http', 'ws');
  11. var url = protocol + '//' + location.host + '/echo-with-no-extension';
  12. worker.port.onmessage = function (evt) {
  13. log(evt.data);
  14. if (evt.data == "DONE") {
  15. document.title = "OK";
  16. } else {
  17. document.title = "FAIL";
  18. }
  19. };
  20. worker.port.postMessage(url);
  21. </script>
  22. </body>
  23. </html>