Skip to content

Instantly share code, notes, and snippets.

@tonyxu-io
Last active June 25, 2018 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonyxu-io/22ecf21b6befd33b88fbdda0bc625971 to your computer and use it in GitHub Desktop.
Save tonyxu-io/22ecf21b6befd33b88fbdda0bc625971 to your computer and use it in GitHub Desktop.
postMessage sample code #snippet
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Index</title>
<button onclick="openWindow()">Open Window</button>
<script type="text/javascript">
function openWindow(){
window.open ("popup.html","popup", "width=350,height=250");
window.addEventListener(
"message",
(event) => {
console.log(event.data)
},
false
);
}
</script>
</head>
<body>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Index</title>
<script type="text/javascript">
window.opener.postMessage({'content': 'your message'}, '*')
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment