如何从 iframe 调用 main window 中 href 中的 Javascript?

How to call Javascript in href in main window from iframe?

我在 iframe 中有一个超链接。

<a href="JavaScript:openRec('8888')">Click here</a>

在父 window 中,我有一个脚本,其中声明了 openRec 函数。如何从 iframe 调用此函数?

勾选https://developer.mozilla.org/en/DOM/window.parent

 <a onclick="parent.openRec('8888');" href="#" >Click here</a>

<a href="JavaScript:parent.openRec('8888');" >Click here</a>

如果父 window 和 iframe 属于同一个域,这应该有效。

在cross-domain场景下可能不起作用。