【问题标题】:How do I close an iframe from an onclick event inside the iframe?如何从 iframe 内的 onclick 事件关闭 iframe?
【发布时间】:2011-11-03 06:54:59
【问题描述】:

我想通过单击 iframe 内的按钮来关闭 iframe,然后返回父页面。

我已搜索但无法获得合适的代码。

谁能帮帮我?

【问题讨论】:

  • 您无法关闭 iframe!但是您需要导航到另一个页面.. window.top.location.href = "newlocation.htm"
  • 你真的不能把按钮放在外面?
  • 第二个@graphox 说的。这将是一个简单的$("#iframe_id").remove() jQuery 调用。

标签: php javascript


【解决方案1】:

试试这个

function closeIframe() [
   var iframe = document.getElementById('someid');
   iframe.parentNode.removeChild(iframe);
}

【讨论】:

    【解决方案2】:

    您需要为 iframe 分配一个 id,例如 <iframe id="someid"...

    那么你需要一个函数来移除 iframe:

    <a href="javascript: window.parent.document.getElementById('someid').parentNode.removeChild(window.parent.document.getElementById('someid'))">Close</a>
    

    【讨论】:

      【解决方案3】:

      此处已对此进行了介绍:Close iframe cross domain 使用了一种更灵活的跨域功能方法。

      【讨论】:

        【解决方案4】:
        <a href="window.parent.document.getElementById('someid').parentNode.removeChild(window.parent.document.getElementById('someid'))">Close</a>
        

        【讨论】:

          【解决方案5】:

          我在按钮 onclick 功能中有这样的东西:

          parent.location.reload();  
          

          我想这可能会对你有所帮助:

          var theFrame=parent.getElementById("iframeId");  
          theFrame.parentNode.removeChild(theFrame);
          

          【讨论】:

            【解决方案6】:

            iframe 是一个棘手的问题,但我和他们一起玩得很开心。当尝试从“顶部”文档访问 iframe 时,您将使用:

            top.iFrameToClose = top.document.getElementById("myiFrame"); top.iFrameToClose.offsetParent.removeChild(top.iFrameToClose);

            希望对你有所帮助……

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2021-08-26
              • 2011-10-08
              • 2013-01-22
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多