Javascript examples for DOM HTML Element:IFrame
The contentDocument property returns the Document object from an iframe element.
You can use the document reference in the host window.
The contents of a document can noly be accessed if the two documents are located in the same domain.
A reference to the document object. If there is no document, the returned value is null
The following code shows how to change the background color of the document contained in an iframe:
<!DOCTYPE html> <html> <body> <iframe id="myframe" src="http://java2s.com"></iframe> <p id="demo"></p> <button onclick="myFunction()">Test</button> <script> function myFunction() {//from w ww . j a v a2 s.c o m var x = document.getElementById("myframe"); var y = x.contentDocument; y.body.style.backgroundColor = "red"; } </script> </body> </html>