IFrame pass values and Get Value
1. Parent page.
<script>
// Here "addEventListener" is for standards-compliant web browsers and "attachEvent" is for IE Browsers.
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var eventer = window[eventMethod];
// Now...
// if
// "attachEvent", then we need to select "onmessage" as the event.
// if
// "addEventListener", then we need to select "message" as the event
var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";
// Listen to message from child IFrame window
eventer(messageEvent, function (e) {
alert("from mvc");
alert(e.data);
// Do whatever you want to do with the data got from IFrame in Parent form.
}, false);
</script>
2. Child page/ Iframe page
<script language="javascript">
function test()
{
window.parent.postMessage("Hello From IFrame", "*");
}
</script>
<div id="divTest" onclick="test();">
This is test
</div>