Last active
June 25, 2018 03:19
-
-
Save tonyxu-io/22ecf21b6befd33b88fbdda0bc625971 to your computer and use it in GitHub Desktop.
postMessage sample code #snippet
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 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> |
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 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