5

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> 
1
  • 1
    Yep, this falls under the Same Origin Policy. Commented Oct 29, 2011 at 3:14

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.