CodeMonkey1313
CodeMonkey1313

Reputation: 16011

JQuery iframe contents cross-domain

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>

Upvotes: 5

Views: 4266

Answers (1)

Kevin B
Kevin B

Reputation: 95031

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.

Upvotes: 8

Related Questions