【问题标题】:Iframe closing without refreshing the main page that contains the iframeiframe 关闭而不刷新包含 iframe 的主页
【发布时间】:2012-10-07 20:12:21
【问题描述】:

我在页面中使用 iframe,其中 iframe 看起来像主 asp.net 页面上的 div。在 iframe 页面中,我有一个关闭按钮,当我单击关闭按钮时,我正在 iframe 页面中调用一个 javascript 函数,其代码如下:

window.location.href = "页面名称.aspx";

此行关闭 iframe,但包含 iframe 的主页在关闭 iframe 后会刷新,所以....

window.close();

但它不起作用。关闭 iframe 的主要问题是关闭 btn 在 iframe 页面中它自己所以如果我编写代码来关闭 iframe 页面中的 iframe 不起作用.....

主要问题是 iframe 关闭 btn 应该像 div 关闭 btn 一样工作,这意味着当我单击关闭 btn 时,div 可以设为不显示但 iframe 当 iframe 值可以访问时,如何使其关闭包含 iframe 但该 iframe 页面无法获取 iframe 名称的主页...

那么,你能帮我解决这个问题吗.. 关闭 iframe 而不刷新包含 iframe 的主页。提前谢谢你!

【问题讨论】:

    标签: javascript asp.net iframe


    【解决方案1】:

    你控制父页面吗?您可以将脚本关闭父级中的 iframe。所以,在父页面中你有

    function myCloseIframeFunction(){
      /*close iframescript*/
    }
    

    然后从 iframe 页面调用 parent.myCloseIframeFunction()。

    【讨论】:

    • 非常感谢您的解决方案有效.... !!!我正在打电话,因为你告诉 iframe 关闭函数作为 parent.myCloseIframeFunction()... 它有效!非常感谢!!!
    • 实际上,这在 Firefox 和 Chrome 中都可以正常工作,但在 IE8 中,当我使用此代码时,当我第一次单击关闭按钮时它工作正常,但第二次单击以打开 iframe iframe没有打开...它在 IE 控制台中打开框架时显示第一个错误:LOG:应用程序配置不允许给定 URL。:应用程序的设置不允许一个或多个给定 URL。它必须与网站 URL 或画布 URL 匹配,或者域必须是应用程序域之一的子域。你能帮忙提前谢谢你!!
    • 我能得到一个链接吗?这听起来像是一个跨域错误,因为 iframe 的域与 iframe 的域不匹配,这只是跨域通信的问题。
    【解决方案2】:

    Page which is being called in Iframe..中编写以下Javascript函数。在关闭按钮客户端单击事件上调用此函数...

          function close()
           {
                    var ifr = parent.document.getElementById(IframeId);
                    ifr.parentNode.removeChild(ifr);
           }
    

    【讨论】:

      猜你喜欢
      • 2011-04-28
      • 2014-03-23
      • 1970-01-01
      • 1970-01-01
      • 2012-02-06
      • 2015-03-11
      • 1970-01-01
      • 2012-05-04
      • 2013-05-22
      相关资源
      最近更新 更多