Accessing iFrame content from parent HTML page using jQuery

I got stuck on this one once, so I decided to write my own article.

To access the content of any iframe on your html page, you can use following:

$('#frameID').contents().find('#someElement').html();

Note, both iframes must be hosted on the same domain, otherwise you will get error, similar to this one:

Error: Permission denied for <http://localhost> to get property HTMLDocument.nodeType from <http://www.example.com>.

Neat workaround for this issue is described on Michael Mahemoff's blog, in article Cross-Domain Communication with IFrames.

Did you like my article? Share it!
Share/Bookmark

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <csharp>, <css>, <html>, <javascript>, <vb>, <vbnet>, <xml>. Beside the tag style "<foo>" it is also possible to use "[foo]".

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters (without spaces) shown in the image.
served by y.co.uk