简体   繁体   中英

To find topmost parent window from the child window

I use web application

From my main application,I opened child window C1 and again opened another child window C2 from C1 . If i close the the C1 window, I'm not able to find the top most main application.

Actually i wanted to redirect the Main application to different page if a hyperlink is clicked on the child window.This is working good until i close C1 which is a parent of C2

Any help is greatly appreciated

@Mey, without the benefit of seeing your code it will be difficult to pinpoint what your problem is. That said, window.top is a reference to the topmost window. It seems to be supported by all major browser (see here ).

You're absolute correct. This does not work on windows created by window.open() . How about this solution: have the opener window set a property on the opened window to keep track of the top most window, immediately after open. That way if any of the intermediate window is closed the opened window already has a reference to the top most window. Let me show you what I mean.

From top most window:

var c1 = window.open(...);
c1.window.topMost = window;

From first popup: c1

var c2 = window.open(...);
c2.window.topMost = window.topMost;

From second popup: c2

var c3 = window.open(...);
c3.window.topMost = window.topMost;

Now, let say you close c1 or c2 , c3 will still have a reference to window.topMost .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM