I want to read iframe contents that have loaded third-party URL.
I can postMessage simple string from iframe to form. But want to pass innerHtml or want to access it from an unload callback. It always gives cross-origin. Please let me know how to access the HTML of the remote site and send it to the form?
HTML code as below:
// here somehow want to send html of iframe......<p><a href="http://thirdparty_url.com/" target="myFrame">ICWT Page</a></p>
scripts and postmessage code:
<script type="text/javascript">
function on_load(iframe,mystring, mywindow) {
var win = (iframe.contentWindow || iframe.contentDocument);
// or here want to access HTML of iframe and post to form.
alert(mystring);
mywindow.postMessage(mystring, "*");
};
function listener(event) {
alert(event.data);
}
if (window.addEventListener) {
window.addEventListener("message", listener, false);
}
else {
attachEvent("onmessage", listener);
}
</script>
Or send innerHtml from iframe to on_load();
< iframe src="index.cfm" name="myFrame" onload="on_load ( this, document.body.innerHtml, window ) ">< /iframe >
Here document.body.innerHtml -> I am trying to assume it has contents of iFrame which has loaded third party url.