I am a newcomer to Javascript and web programming in general. I am trying to figure out web workers, and have the following code (running in chrome):
worker_example.html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="worker_example.js"></script>
</head>
<html>
worker_example.js
var worker = new Worker("worker.js");
worker.addEventListener('message', function(e) {
document.write("hello");
}, false);
worker.postMessage("");
worker.js
// self.postMessage("");
My question is why doesn't worker.postMessage("")
trigger the event? If I uncomment the single line in worker.js, however, everything works fine.