Is it possible to use jQuery to access the contents of an iframe when the iframe source is on a different domain? I'm not looking to modify the contents, just read in the html when the iframe is finished, so that's why I'm not sure if this falls under the Same Origin Policy.
ex:
domain : http://www.example-A.com/
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$("#helper").append("<iframe src='http://www.citizensbank.com' ></iframe>");
getContents("#helper");
});
function getContents(iframeID) {
if ($(iframeID + " iframe").context.readyState != "complete") {
setTimeout("getContents('" + iframeID + "');", 200);
} else {
alert($(iframeID + " iframe").contents().html());
}
}
</script>
<div id="helper"><iframe src="http://www.example-B"></iframe></div>
No, it is not possible to read the contents of an iframe using javascript if the iframe's src is a different domain from the parent page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With