MDN self-hosted library · e01.org

HTMLIFrameElement: contentDocument property

HTML DOM

Open notebook · 1 cells web-api-instance-property upstream source

HTML DOM

The contentDocument read-only property of the HTMLIFrameElement interface returns a Document (that is, the active document in the inline frame's nested browsing context) if the iframe and the iframe's parent document are Same Origin, else returns null.

Example of contentDocument

const iframeDocument = document.querySelector("iframe").contentDocument;

iframeDocument.body.style.backgroundColor = "blue";
// This would turn the iframe blue.

Specifications

Browser compatibility