As you can see you have the same mechanism for both worker-to-main and main-to-worker messages.
- the
postMessagemethod for sending messages - the
onmessagemember for defining the handler that receives the messages
In the main script:
worker.postMessage(data);
In the worker script:
self.addEventListener("message", function(e) {
// the passed-in data is available via e.data
}, false);
… or just…
onmessage = function(e) {
// the passed-in data is available via e.data
};