Skip to content

Instantly share code, notes, and snippets.

@deanhume
Created November 29, 2011 11:34
Show Gist options
  • Save deanhume/1404507 to your computer and use it in GitHub Desktop.
Save deanhume/1404507 to your computer and use it in GitHub Desktop.
HTML5 WebWorkers
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<!DOCTYPE HTML>
<html>
<head>
<title>Web Worker Example</title>
<script src="<%= Url.Content("~/scripts/modernizr-1.7.min.js") %>"></script>
</head>
<body>
<p>Result: <output id="result"></output></p>
<script>
if (Modernizr.webworkers) {
var worker = new Worker('<%= Url.Content("~/scripts/LogStats.js") %>');
worker.onmessage = function (event) {
document.getElementById('result').textContent = event.data;
};
worker.onerror = function (event) {
console.log(event.message, event);
};
} else {
alert("Sorry!! you do not have web workers support.");
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment