Get and modify content of an Iframe
It is important to know that the page that is included in IFrame must be on the same server as the main page which contains it, or else it will not work for security reasons.
Going straight to the point, to get and modify the content of an IFrame, you can use the contentWindow property, it returns the "window object" of a specified frame or iframe.
Here's an example to understand how to apply this property.
1) First create a file "ifr.htm" that will contain the HTML code of the page that will be displayed in the IFrame.
<html> <head><title>Iframe page</title></head> <body> Content to be displayed in iframe ... </body> </html>
- Necessary explanations are in the script code.
- This example will display the following result:
The main page
This method is presented in the next tutorial, in which you will see how to get and modify the content of an IFrame by accessing a JS script that is created in another IFrame.