Javascript Can';t从iframe调用父函数

Javascript Can';t从iframe调用父函数,javascript,jquery,html,iframe,parent,Javascript,Jquery,Html,Iframe,Parent,我试图调用2个函数setListener()和addNewBox()从iframe中 我到处找,什么都试过了,但都没法用 我无法访问父级的头部,因为它是通过php以块的形式构造的 这是父文件外观的粗略模型 <head> <?php require "head.html" ?> </head> <body> <?php require "content.html" ?> </body> content.html模型: &

我试图调用2个函数
setListener()
addNewBox()从iframe中

我到处找,什么都试过了,但都没法用

我无法访问父级的头部,因为它是通过php以块的形式构造的

这是父文件外观的粗略模型

<head>
<?php require "head.html" ?>
</head>
<body>
<?php require "content.html" ?>
</body>

content.html模型:

<!-- a bunch of boring divs -->
<iframe src="image_editor.html"></iframe>
<script> /* random ajax */ </script>
<script>
$(document).ready(function(e) {
    //init
    setListener();
    addNewBox();

    function setListener()
    {
            //MAGIC HAPPENS
        }

        function addNewBox()
    {
            //GREATER MAGIC HAPPENS
        }
}
</script>
<body>
<form id="image_form">
<input type="submit" value="Submit"/>
</form>
<script>
$(document).ready(function(e) {
    $("#image_form").submit(function(e) {
            //MAGIC HAPPENS HERE

            //re-adds listeners
            window.parent.addNewBox();
            window.parent.setListener();
        }
</script>
</body>

/*随机ajax*/
$(文档).ready(函数(e){
//初始化
setListener();
addNewBox();
函数setListener()
{
//奇迹发生了
}
函数addNewBox()
{
//更大的魔法发生了
}
}
image_editor.html模型:

<!-- a bunch of boring divs -->
<iframe src="image_editor.html"></iframe>
<script> /* random ajax */ </script>
<script>
$(document).ready(function(e) {
    //init
    setListener();
    addNewBox();

    function setListener()
    {
            //MAGIC HAPPENS
        }

        function addNewBox()
    {
            //GREATER MAGIC HAPPENS
        }
}
</script>
<body>
<form id="image_form">
<input type="submit" value="Submit"/>
</form>
<script>
$(document).ready(function(e) {
    $("#image_form").submit(function(e) {
            //MAGIC HAPPENS HERE

            //re-adds listeners
            window.parent.addNewBox();
            window.parent.setListener();
        }
</script>
</body>

$(文档).ready(函数(e){
$(“#图像表格”)。提交(功能(e){
//魔法在这里发生
//重新添加侦听器
window.parent.addNewBox();
window.parent.setListener();
}
我已经尝试了我能在网上找到的每一个解决方案,从使用top到以公共格式(window.myFunction=function(){};)重新声明父函数

如果您有任何建议,我将不胜感激

谢谢

更新:
经过一些调试后,调用不起作用的原因似乎是因为执行在它们之前停止了一行。不知何故,这一行“$(“.new”、window.parent.document).remove();”破坏了一切。我现在必须找出这一行。我感谢您的帮助。

发生这种情况至少是因为
setListener()
addNewBox()
不在
窗口的全局范围内。父项
。若要解决此问题,您需要将它们移出
$(文档)。就绪(函数(e){…}())
这是因为它们位于
$(文档)。就绪(函数(){});

您可以这样修复它:

$(window.parent).bind(setListener);
$(window.parent).bind(addNewBox);

希望能有所帮助!

不,没有相关内容。如果其中一个在到达代码的这一部分之前停止执行?不,这只是警告fb按钮未加载。不,但你是对的。就在“$(“.new”、window.parent.document).remove();”之前的行阻止了出于任何原因进一步执行任何内容。