Skip to content

Instantly share code, notes, and snippets.

@devdays
Created December 2, 2014 05:30
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 devdays/79141ab5506aeca47e2f to your computer and use it in GitHub Desktop.
Save devdays/79141ab5506aeca47e2f to your computer and use it in GitHub Desktop.
Messaging -- post message to the iFrame
<!DOCTYPE html>
<html>
<head>
<title>Post Message</title>
</head>
<body>
<form id="the-form" action="/">
<input type="text" id="my-message" value="Your message">
<input type="submit" value="postMessage">
</form>
<iframe id="my-iframe" src="postMessageTarget.html"></iframe>
<script>
window.onload = function () {
var iframeWin = document.getElementById("my-iframe").contentWindow,
form = document.getElementById("the-form"),
myMessage = document.getElementById("my-message");
myMessage.select();
form.onsubmit = function () {
iframeWin.postMessage(myMessage.value, "/");
return false;
};
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment