如何从子窗口jquery调用父窗口函数?

我只需要在用户关注子窗口时调用父窗口中的函数。 我在父窗口中有这个代码,

   function CallParent() { alert(" Parent window Alert"); }   Click here to open the child window   

和贝娄代码在我的孩子窗口,

     jQuery(document).ready(function(){ window.opener.CallParent(); });    

This is Child window

所以..在这种情况下,我认为CallParent()将在子窗口打开后触发。 但似乎没有用。 任何人都可以给我任何提示,使这个脚本工作,或任何更好的方法来做到这一点。

尝试以下内容:

parent.html

     Click here to open the child window   

child.html

       

This is Child window

您不应该在父项上执行此操作,否则opener.CallParent()将无效,执行window.CallParent使CallParent可用作窗口范围:

 function CallParent() { alert(" Parent window Alert"); } 

然后你可以简单地调用opener.CallParent(); 不是window.opener.CallParent();

用这个

 window.parent.CallParent(); 

代替

 window.opener.CallParent(); 

window.parent保存对当前窗口或子帧的父级的引用。

如果窗口没有父窗口,则parent属性是对自身的引用。

加载窗口时,其父窗口是嵌入窗口的元素的窗口。

参考: https : //developer.mozilla.org/en-US/docs/Web/API/Window/parent