Skip to content

Instantly share code, notes, and snippets.

@rwaldron
Created May 17, 2010 23:30
Show Gist options
  • Save rwaldron/404377 to your computer and use it in GitHub Desktop.
Save rwaldron/404377 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Workers: Basic Demo</title>
<script>
document.addEventListener('DOMContentLoaded', function () {
var worker = new Worker('worker-javascript-file.js');
worker.postMessage('Hello Worker!');
worker.addEventListener('message', function (event) {
console.log(event.data); // will log "Hello Main Window!"
}, false);
}, false);
</script>
</head>
<body>
</body>
</html>
self.addEventListener('message', function (event) {
this.postMessage( event.data.replace('Worker', 'Main Window') );
});
@fearphage
Copy link

Won't it output Hello Main Window!?

@rwaldron
Copy link
Author

rwaldron commented Oct 7, 2010

Yep! thanks dude.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment