Code of a page inserted in DFrame:  Access mainPage

Goal: To reach the variables, objects and functions of mainPage from a page inserted in a DFrame.

The Javascript code of a page inserted in a DFrame can reach mainPage to use a value, to run a function or a method on a DFrame.

Way: Use 'mainPage' keyword

The access to mainPage will be done by the intermediary of the 'mainPage' keyword.

 Example 1 :

In a page inserted in a DFrame:

alert(mainPage.location.href)

return the initial address of the browser, the one that allowed the loading of mainPage

Example 2 :

In mainPage :

var value = 'this is stored in mainPage'

In a page inserted in a DFrame:

alert(mainPage.value)

return 'this is stored in mainPage'

Example 3 :

In a page inserted in a DFrame:

mainPage.openNewDFrame()

start the openNewDFrame function of mainPage.

Example 4 :

In a page inserted in a DFrame:

mainPage.dFrameName.setURL(url)

start the setURL method of the dFrameName object.

Remark:

The 'mainPage' keyword is a handle on the window object containing the page we used to call 'mainPage'.