js关闭iframe中的子界面

界面A中有一个按钮,同时嵌套了一个iframe(给iframe的src="www.baidu.com"),我希望点击按钮可以实现关闭iframe中的界面,各位大哥有人知道如何实现吗?

第1个回答  推荐于2016-12-04
iframe放在一个DIV中 设一个id
var iframeDiv=document.getElementById("DivId");
document.body.removeChild(iframeDiv);本回答被提问者采纳
第2个回答  2011-08-30
主页面:
<script type="text/javascript">
function openFrm(url)
{
var frm =divObj.getElementById("myFrm");
if(frm==null || frm=="undifined"){
frm=docment.createChild("iframe");
frm.setAttribute("id","myFrm");
document.getElementById("divFrm").appendChild(frm);
}
frm.src=url;
}
function closeFrm()
{
var divObj=document.getElementById("divFrm");
var frm = document.getElementById("myFrm");
divObj.removeChild(frm);
}
</script>
<input type="type" id="btnClose_p" onclick="openFrm('www.baidu.com');" value="关闭iframe" />
<div id="my_div">
<input type="hidden" id="hdClose" onclick="closeFrm();" />
</div>
iframe页面:
<script type="text/javascript">
function close()
{
window.parent.document.getElementById("hdClose").click();
}
</script>

<input type="type" id="btnClose_c" onclick="close();" value=" 在iframe中关闭自己 " />

二楼正解:实现成功!
第3个回答  2011-08-22
关闭 是不行。只能转到其他页面,或则提供空白页面 about:blank。
第4个回答  2011-08-23
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>

<ul id="test">
<li><a href="javascript:load('http://www.baidu.com')">百度</a></li>
<li><a href="javascript:load('http://www.google.com')">谷歌</a></li>
</ul>
<iframe scr="index.html" id="if" style="width:300px;height:400px;border:0px;" ></iframe>
<script type="text/javascript">
function load(url){ //用这种方法就行了
document.getElementById("if").src=url; // if为iframe标签的ID,宽度、高度、边框这些自己调
}
</script>

</body>
</html>
试下,你说的是不是这效果
第5个回答  推荐于2018-03-11
window.parent.location.reload();
本回答被网友采纳
相似回答