Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从iframe在主窗口的href中调用Javascript?_Javascript_Html_Iframe_Hyperlink_Anchor - Fatal编程技术网

如何从iframe在主窗口的href中调用Javascript?

如何从iframe在主窗口的href中调用Javascript?,javascript,html,iframe,hyperlink,anchor,Javascript,Html,Iframe,Hyperlink,Anchor,我在iframe中有一个超链接 <a href="JavaScript:openRec('8888')">Click here</a> 在父窗口中,我有一个脚本,其中声明了openRec函数。如何从iframe调用此函数?检查 或 如果父窗口和iframe属于同一个域,则应该可以这样做 它可能在跨域场景中不起作用。在iframe html的头部使用简单的父js脚本链接。因为它已经在父级中声明为函数。我不能这样做,因为该代码实际上是本机代码如果您在进行此类交互

我在iframe中有一个超链接

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

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

检查



如果父窗口和iframe属于同一个域,则应该可以这样做


它可能在跨域场景中不起作用。

在iframe html的头部使用简单的父js脚本链接
。因为它已经在父级中声明为函数。我不能这样做,因为该代码实际上是本机代码如果您在进行此类交互,iFrame可能不是解决这个问题的方法。这取决于域。如果它们是独立的域,您可能不能也应该反转逻辑,以便父级控制iframe,而不是相反。因此父级应该编辑iframe,因为iframe不能调用父级内部的任何函数。如果它们是同一个域,为什么还要使用iframe?我的要求是在同一个域中使用iframe。如果您有任何解决方案,请告诉我们它属于同一个域,如果我在href中传递parent.openRec有什么区别?您也可以这样做。当我将它连接到我的域链接时,就像它没有调用我的javascript函数一样,它作为一个超链接工作,意味着重定向到urlTry
 <a onclick="parent.openRec('8888');" href="#" >Click here</a>
<a href="JavaScript:parent.openRec('8888');" >Click here</a>