views:

175

answers:

2

Hello,

We have a web application where we're using "top.document" since this application uses iframes and sometimes we must reach the top document.

The problem started now since we need to integrate this application in a website and we put it inside an iFrame in this very site. Since the application uses "top.document" it is reaching the site's "document" instead of the application's "top".

Do you have any ideas to help us solve the problem?

Thanks in advance!

Rui

A: 

The approach to ensuring that you are looking at the correct window is to know where you are within the framed application.

For example, let us say the “main frame” is the root of the site. Within the main frame, additional ‘iFrames’ are defined. The pages that are loaded in these additional frames need to know where they are in the frame hierarchy.

So you see, understanding where you are in the hierarchy of frames and pop-ups will allow you to properly backtrack and define references to functions and objects contained within windows in previous pages/frames.

Adding some Javascript code to give you an idea:

if (window.self){
    if (window.top == window) {
         if (window.name == "main_frame"){
     MainFrameRef = window.top;
     return MainFrameRef;
         }else{
     return false;
         }
         }
}
Ralph Wiggum
+1  A: 

Assuming your iframe is one level deep:

parent.document

or, if it's deeper:

parent.parent.parent.parent.document

but I really hope it's not that deep ;-)

NickFitz
Ok, but we have javascript functions that are called at different points in the iframe hierarchy, so the solution must be more flexible...
Rui
You will have to sweep through ALL pages in your "Inner" website and modify the top.document references to parent.document etc. depending on the level of the page.
Ralph Wiggum