Skip to content

Instantly share code, notes, and snippets.

Created Dec 25, 2016
What would you like to do?
A simple call and back using a webworker
document.onload = function () {"Document loaded");
var worker;
function runWorker() {
if (window.Worker) {
worker = new Worker("Worker.js");
worker.onmessage = function (msg) {
document.querySelector("#resultarea").innerHTML = msg;
} else {
console.debug("Web workers are not supported");
function sendMessage() {
if (worker) {
<script src="app.js"></script>
<button onclick="runWorker()">Run worker job</button>
<button onclick="sendMessage()">Send message to worker</button>
<textarea name="" id="resultarea" cols="30" rows="10"></textarea>
onmessage = function(event) {
console.debug("posting message: ",;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment