【问题标题】:How to refresh iframe parent page after a submit in the iframe?在 iframe 中提交后如何刷新 iframe 父页面?
【发布时间】:2009-12-07 15:25:17
【问题描述】:

我在一个页面中有 iframe,这个 iframe 包含一个提交按钮,它会执行一些功能。

我想要的是:iframe提交完成后,调用父页面刷新。

我知道如何刷新它:

parent.location.reload();

但我不知道提交完成后该怎么做。

【问题讨论】:

    标签: asp.net javascript html iframe


    【解决方案1】:

    在 iframe 上使用 onload 事件处理程序。当它在提交后触发时,执行你的top.location.reload...

    // In parent
    window.onload = function() {
      document.getElementById("MY_IFRAME").onload = function() {
        top.location.reload();
      }
    }
    

    【讨论】:

    • 可爱!非常感谢。
    【解决方案2】:

    我通过在所有方法完成后在后面的代码中添加这行代码解决了这个问题:

        ScriptManager.RegisterStartupScript(this, typeof(string), "script", 
    "<script type=text/javascript>
    parent.location.href = parent.location.href;</script>", false);
    

    我没有写parent.location.reload() 并写parent.location.href = parent.location.href 的原因是不要将数据发送两次到服务器,因为我想要一个新的页面加载。

    【讨论】:

      【解决方案3】:

      提交表单是对 iframe 中文档的最终操作。提交表单后,该页面已“提交”并且不再处于活动状态。如果先刷新父级,则会丢失 iframe。在 iframe 中提交的那一刻,您将无法再与父级对话。

      您可以在此处执行以下操作之一:

      • 在您提交表单时定位 PARENT,然后父级将在该页面的新 iframe 中拥有您想要的任何内容。
      • 让 iframe 中的结果页面在结果页面上使用 JavaScript 重新加载父页面。

      【讨论】:

        【解决方案4】:

        如果您只想刷新父页面的某些部分而不需要刷新整个页面,并且大多数情况下都是这种情况,因为这种方法不会重新加载 iframe 本身,您可以调用来自子页面的 javascript 函数。

        window.parent.myFunctionInParent('my argument');
        

        指导你的资源在这里:Refresh parent page partially from iframe

        谢谢。

        【讨论】:

          猜你喜欢
          • 2013-12-28
          • 2013-03-20
          • 2012-05-22
          • 2013-04-20
          • 2011-04-28
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多