Messaging -- post message to the iFrame
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> | |
<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