Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
Last active November 26, 2015 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nolanlawson/f71571e8770ba7174566 to your computer and use it in GitHub Desktop.
Save nolanlawson/f71571e8770ba7174566 to your computer and use it in GitHub Desktop.
Test location.origin in a web worker
<html>
<body>
<h1>Test location.origin in a web worker</h1>
<pre id="output"></pre>
<script>
(function () {
var output = document.getElementById('output');
output.innerHTML += 'location.origin in main thread: ' + location.origin + '\n';
var worker = new Worker('worker.js');
worker.addEventListener('message', function (e) {
output.innerHTML += e.data;
});
worker.postMessage({});
})();
</script>
</body>
</html>
self.addEventListener('message', function () {
self.postMessage("location.origin in worker: " + location.origin);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment