Skip to content

Instantly share code, notes, and snippets.

@ryanbaumann
Forked from szilardhuber/frame.html
Created January 25, 2018 19:30
Show Gist options
  • Save ryanbaumann/8a9d21d8ef549d57a0417b12dee87246 to your computer and use it in GitHub Desktop.
Save ryanbaumann/8a9d21d8ef549d57a0417b12dee87246 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("https://bl.ocks.org/szilardhuber/raw/f6064173b643b2a9a16cc1a0b5f773ef/c5d4f8a8add0874b1e8d520686dca371d8c63fa1/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