script id="worker1"
<script id="worker1" type="javascript/worker">
// This script won't be parsed by JS engines because its type is JavaScript/worker.
// Simple code to calculate prime number and send it back to the parent page.
self.onmessage = function(e) {
self.postMessage("<h3>Worker: Started the calculation</h3><ul>");
var n = 1;
search: while (n < 500) {
n += 1;
for (var i = 2; i <= Math.sqrt(n); i += 1)
if (n % i == 0)
continue search;
// found a prime!
postMessage("<li>Worker: Found another prime: " + n + "</li>");
}
postMessage("</ul><h3>Worker: Done</h3>");
}
</script>