Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery iframe contents cross-domain

Tags:

jquery

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>
like image 315
CodeMonkey1313 Avatar asked Oct 29 '11 02:10

CodeMonkey1313


1 Answers

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.

like image 139
Kevin B Avatar answered Oct 18 '22 21:10

Kevin B