Index

How do I get the content loaded in an iframe?

You can get the content of a iframe using two different methods.

First, you can use the windows's frames list to get a reference to a specific frame. For example:

window.frames[0].document

This line will get the first frame in the window and return its document. You can also replace the index with a name corresponding to the name attribute on an iframe.

In chrome installed applications, you can also use the contentDocument property of the iframe. The following demonstrates both methods. Both variables 'method1' and 'method2' will have the same value.

<script>
function getContent()
{
  var method1 = window.frames['hello'].document;
  var iframe=document.getElementById("hello");
  var method2 = iframe.contentDocument;
}
</script>
<iframe id="hello" name="hello" src="hello.xul"/>
Copyright © 1999 - 2005 XULPlanet.com