Skip to content

Instantly share code, notes, and snippets.

@bacanu
Last active March 7, 2017 06:40
Show Gist options
  • Select an option

  • Save bacanu/a17573714ed9ea4a476607724fd467f9 to your computer and use it in GitHub Desktop.

Select an option

Save bacanu/a17573714ed9ea4a476607724fd467f9 to your computer and use it in GitHub Desktop.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>Hello World</h1>
<script>
window.addEventListener("message", receiveMessage, false);
function receiveMessage(event)
{
console.log(event);
}
</script>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<iframe src="iframe.html" id="theiframe" frameborder="0"></iframe>
<script>
var iframe = document.getElementById("theiframe").contentWindow;
iframe.postMessage("hello", "*"); // doesnt work, should only send message after iframe is loaded
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment