0

From the Firebug JavaScript console is it possible to access the content of an <iframe> object whose src property is set to about:blank? I've tried with:

var b=document.getElementById("iframe_ID");
console.log(b.innerHTML);

but it returns

(an empty string)
tic
  • 4,009
  • 15
  • 45
  • 86
  • I thought `about:blank` is supposed to be void of content. What would you expect instead of an empty string? – merlin2011 Jul 25 '14 at 21:46
  • I want to do some test for a web page that is not written by me. – tic Jul 25 '14 at 22:11
  • Looks like the question is actually unrelated to about:blank but rather asking about how to access an iframe's document via JavaScript, so probably a duplicate of http://stackoverflow.com/questions/14944699/accessing-the-document-object-of-a-frame-with-javascript. – Sebastian Zartner Jul 25 '14 at 23:20

1 Answers1

1

With document.getElementById("iframe_ID").innerHTML you just get the HTML content within the iframe element of the current document, not the iframe's document. I.e. if you have your iframe defined like this:

<iframe src="someDocument.html" id="iframe_ID"></iframe>

you get the contents between the opening <iframe> tag and the closing </iframe> tag, i.e. an empty string in this case.

To access the iframe's content you need to call this:

document.getElementById("iframe_ID").contentDocument.documentElement.innerHTML

See also Accessing the document object of a frame with JavaScript.

Though note that there are some security restrictions when trying to access the iframe's content as described in an answer to a similar topic.

Community
  • 1
  • 1
Sebastian Zartner
  • 18,808
  • 10
  • 90
  • 132