【问题标题】:Controlling the top parent window from iframe with jquery or javascript使用 jquery 或 javascript 从 iframe 控制顶部父窗口
【发布时间】:2010-09-08 18:50:46
【问题描述】:

我的网站上有一个页面,其中有一个空白文本字段。旁边是一个打开 iframe 的按钮(使用颜色框)。此 iframe 显示文件列表 - 每个文件旁边都有一个按钮,通过调用以下函数将文件名放入父窗口的文本字段中:

function returnImage(file){

  $('#input_text_id', window.parent.document).val(file);
  parent.$.fn.colorbox.close();

}

这很好用,但是当我单击 iframe 中的文件夹时会出现问题。这会导致 iframe 中的页面加载不同的文件页面。在此之后,该功能不再起作用。

无论如何,我可以使用 jquery 访问最顶层的父页面并控制它吗?所以我们会有类似的东西:

function returnImage(file){

  $('#input_text_id', theoriginalwindow.document).val(file);
  parent.$.fn.colorbox.close();

 }

希望这是有道理的,如果您需要更多信息,请告诉我。

谢谢

【问题讨论】:

    标签: javascript jquery iframe parent-child


    【解决方案1】:

    在顶部窗口中:

    <script>
       function returnImage(file, doc){
           $('#input_text_id', doc).val(file);
           $.fn.colorbox.close();
       }
    </script>
    

    来自 iframe:

    <script>
        top.returnImage(file, document); // top is top parent window.
    </script>
    

    【讨论】:

      【解决方案2】:

      使用top

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多