


The text changed from iframe 2')">Action iframeģ) The last step is to create the parent page, "main.html", that will contain and display the two IFrames.I have a modal window but I want to set up a close function so that when the user clicks on the "button", it will close the modal window.

Function that replace the content of the DIV "div_ifr1" with the value of its parameterĭocument.getElementById('div_ifr1').innerHTML = txt Ģ) Now create the page "ifr2.htm", for the second IFrame, with a button that calls a JavaScript function that will get the content of the first iframe "ifr1.html", and the value of a variable defined in it ( see the comments in script). Here's an example ( explanations are in the code).ġ) First, create a file named "ifr1.htm", that will represent the page included in the first IFrame. element - can be an object, a variable, or function in the " iframe_name". Var var_name = parent.iframe_name.element Going straight to the point, to get and change the content of an IFrame through another IFrame, you use their common base, the Main Page, also named " Parent", using the parent property and the name of the IFrame that will be accessed (name that is specified in the " name" attribute in the tag). It is important to know that the pages that are included in the IFrames must be on the same server as the main page, or else it will not work for security reasons. This tutorial shows you how to get and change the content of an IFrame, by accessing a variable and a function defined in it, through a button and a Javascript script created in another IFrame. When you click on the buton 'Action iframe' (displyed in the second iframe), the function 'fifr2()' is called.It gets and displays in an Alert window the content of the IFrame 1, then gets the value of the variable 'varifr1', calls the function 'fifr1()' (created in the first IFrame), passing it a text that will replace the content of a tag in IFrame 1.
