Created
August 4, 2016 13:16
-
-
Save gareth/41cb1644638c6c956d61297f419b091b to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> | |
<title>Launcher</title> | |
<script src="https://code.jquery.com/jquery-3.1.0.min.js" type="text/javascript" charset="utf-8"></script> | |
<script type="text/javascript" charset="utf-8"> | |
$(function() { | |
var receiver; | |
$('#launch').click(function() { | |
if(receiver) { receiver.close(); } | |
receiver = window.open('/target.html', 'target', 'width=200,height=200'); | |
}) | |
$('#send').click(function() { | |
if(receiver) { | |
receiver.postMessage("Hello!", "*") | |
} | |
}) | |
}) | |
</script> | |
</head> | |
<body> | |
<button id='launch'>Launch!</button> | |
<button id='send'>Send!</button> | |
</body> | |
</html> |
This file contains hidden or 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> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> | |
<title>Target</title> | |
<style> | |
p { background: #eee; padding: 5px; font-family: sans-serif; } | |
</style> | |
<script src="https://code.jquery.com/jquery-3.1.0.min.js" type="text/javascript" charset="utf-8"></script> | |
<script type="text/javascript" charset="utf-8"> | |
var count = 0; | |
window.addEventListener("message", function(e) { | |
$('body').prepend( | |
$('<p>').text(++count + ' ' + e.data) | |
); | |
}); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment