Output

Log:

Sample Code

This example shows how you can connect to a worker and how a worker sends a message back to the page when it’s connected. Received messages are displayed after "Logs”.

HTML :

  <script>
    function output() {
      var worker = new SharedWorker('test.js');
      var log = document.getElementById('log');
      worker.port.onmessage = function(e) {
        log.textContent += '\n' + e.data;
      }
      return false;
    }
  </script>
  <form>
    <input type="button" value="Click" id="btn" onClick="output()" />
  </form>
  <pre id="log">Log:</pre>