Last active
January 25, 2018 19:32
-
-
Save szilardhuber/f6064173b643b2a9a16cc1a0b5f773ef to your computer and use it in GitHub Desktop.
Iframe worker url test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
</head> | |
<body> | |
<div class="second-row"> | |
<iframe src="frame.html" sandbox="allow-scripts"></iframe> | |
</div> | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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