如何从子窗口调用 parent 的 parent javascript函数。
例子-
父级1具有javascript函数abc()
现在,如何从父级2的子级中触发父级2的子级窗口中的Parent1 Javascript函数。
我尝试了window.parent.parent。仍然没有运气。
提前致谢
最佳答案
不确定您对子窗口的意思。但是我想 window.opener
可能就是您想要的。
// Call abc in the window that opened the current window
window.opener.abc();
更新
还没有尝试过,但是因为
window.opener
是对打开当前窗口的窗口的引用,所以我想您应该能够在该引用上调用opener
属性,以获取对其父对象的引用:window.opener.opener.abc();
如果您想到达最顶层的窗口(根窗口,或您称之为的窗口),则可以使用
window.top
代替:window.top.abc();