Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

contentDocument for an iframe

What exactly does "contentDocument" represent for an iframe (or even the old "frame" element)? Is it equivalent to the "html" element or the "body" element ? What is it's use? And is this property supported across all the browsers?

like image 990
copenndthagen Avatar asked Jul 05 '11 11:07

copenndthagen


People also ask

Can you access Dom inside iframe?

The contentWindow property returns the Window object of an HTMLIFrameElement. You can use this Window object to access the iframe's document and its internal DOM.

How do I get iframe innerHTML?

contentWindow. document. body. innerHTML: It returns the HTML content of iframe body.

Can I get element from iframe?

contents() can get both text nodes and HTML elements. That's why one can get document contents of an iframe by using it. Note that the iframe and page have to be on the same domain.

How do you write inside an iframe?

</i>'); // use this to write something into the iFrame window.


1 Answers

contentDocument represents the document of an iframe (DOM object). It is not equivalent to html since documents have their own properties, however if you type:

myFrame.contentDocument.body 

You will get the body itself.

It is supported in all the browsers, with a tiny modification: for Internet Explorer use

myFrame.contentWindow.document

Enjoy, Nili

like image 169
Nili Avatar answered Oct 03 '22 13:10

Nili