Skip to content

Instantly share code, notes, and snippets.

@szilardhuber
Last active January 25, 2018 19:32
Show Gist options
  • Save szilardhuber/f6064173b643b2a9a16cc1a0b5f773ef to your computer and use it in GitHub Desktop.
Save szilardhuber/f6064173b643b2a9a16cc1a0b5f773ef to your computer and use it in GitHub Desktop.
Iframe worker url test
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="second-row">
I am an IFrame
</div>
<script>
var myWorker = new Worker("worker.js");
myWorker.postMessage([2, 42]);
myWorker.onmessage = function(e) {
let line = document.createElement("h1");
line.innerText = e.data.toString();
document.body.appendChild(line)
};
</script>
<script id="w1">
onmessage = function(e) {
console.log('Message received from main script');
var workerResult = 'Result: ' + (e.data[0] + e.data[1]);
console.log('Posting message back to main script');
postMessage(workerResult);
}
</script>
</body>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="second-row">
<iframe src="frame.html" sandbox="allow-scripts"></iframe>
</div>
</body>
onmessage = function(e) {
console.log('Message received from main script');
var workerResult = 'Result: ' + (e.data[0] * e.data[1]);
console.log('Posting message back to main script');
postMessage(workerResult);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment