<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Ping Pong</title>
<script src="manager.js"></script>
</head>
<body>
<p id="output"></p>
</body>
</html>
//manager.js
window.onload = function() {
var worker = new Worker("worker.js");
worker.postMessage("ping");
worker.onmessage = function (event) {
var message = "Worker says " + event.data;
document.getElementById("output").innerHTML = message;
};
}
//worker.js
onemessage = pingPong;
function pingPong(event) {
if (event.data == "ping") {
postMessage("pong");
}
}