简体   繁体   English

从子窗口中找到最顶层的父窗口

[英]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 . 在主应用程序中,我打开了子窗口C1然后再次从C1打开了另一个子窗口C2 If i close the the C1 window, I'm not able to find the top most main application. 如果关闭C1窗口,则找不到最主要的应用程序。

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 实际上,如果在子窗口上单击超链接,我想将Main应用程序重定向到其他页面。在我关闭作为C2父级的C1 ,这一直很好

Any help is greatly appreciated 任何帮助是极大的赞赏

@Mey, without the benefit of seeing your code it will be difficult to pinpoint what your problem is. @Mey,如果没有看代码的好处,将很难查明问题所在。 That said, window.top is a reference to the topmost window. 就是说, window.top是对最顶层窗口的引用。 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() . 这在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 从第一个弹出窗口: c1

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

From second popup: c2 从第二个弹出窗口: 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 . 现在,假设您关闭c1c2c3仍将引用window.topMost

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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