HTML-删除iframe显示 [英] HTML - Remove iframe Display

查看:85
本文介绍了HTML-删除iframe显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个带有iframe的HTML页面(主页),因此,当我单击按钮时,iframe将显示覆盖整个页面.但是,每当我从iframe中单击返回按钮到主页时,都遇到了如何删除它的问题.

I created an HTML page (main page) with an iframe so when I click the button the iframe will display covering the whole page. But I am having a problem on how to remove it whenever I click the back button from the iframe to the main page.

这是我的代码:

function displayIframe() {
  document.getElementById("iframeDisplay").innerHTML = "<iframe src=\"./iframe/iframe.html\" height=\"100%\" width=\"100%\" ></iframe>";
}

<div id="iframeDisplay"> </div>
<button onclick="displayIframe()">Display Iframe</button>

您能帮我如何通过javascript或jquery关闭iframe吗?

Can you help me on how can I achieve closing the iframe via javascript or jquery

推荐答案

由于框架的来源与包含页面位于同一域(甚至站点),因此您应该能够从框架的代码访问父项.

Since the source of your frame is on the same domain (even site) as the containing page, you should be able to reach from frame's code into the parent.

window.parent.document.querySelector('iframe').style.display = 'none';

这篇关于HTML-删除iframe显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆