Skip to content

Instantly share code, notes, and snippets.

@rwaldron

rwaldron/index.html

Created May 17, 2010
Embed
What would you like to do?
<!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

This comment has been minimized.

Copy link

@fearphage fearphage commented Oct 7, 2010

Won't it output Hello Main Window!?

@rwaldron

This comment has been minimized.

Copy link
Owner Author

@rwaldron 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