如何使用 javascript 删除 iframe 本身 [英] How do I remove iframe within itself by using javascript
本文介绍了如何使用 javascript 删除 iframe 本身的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道有几个类似的问题,但由于无法解决,我不得不用附加的代码再次提出问题.我在 JSF 项目中有两个 .xhtml 文件.一个是 mainPage.xhtml 有一个按钮,可以生成动态 html 代码来创建 iframe(iFramePage.xhtml)并在浏览器上显示;
<!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"xmlns:h="http://java.sun.com/jsf/html"xmlns:f="http://java.sun.com/jsf/core"xmlns:ui="http://java.sun.com/jsf/facelets"><h:头><h:outputStylesheet library="css" name="style.css"/><script type="text/javascript">/** 为 iFramePage.xhtml 创建动态 iframe HTML 代码 **/函数 createIFrameHTML(){document.getElementById("iFrameContainer").innerHTML = '<div id="iframe0"><iframe src="iFramePage.xhtml" width="450px" height="300px"></iframe><;/div>';}/** 关闭 iFrame **/函数删除元素(){/*当我在这个页面内调用时,两行都正常工作,*//*..但是它不能通过从 iFramePage.xhtml 调用 *///document.getElementById("iFrameContainer").removeChild("iframe0");$('iframe0').remove();}</h:head><身体><f:view><h:form id="mainForm"><!-- 控制菜单--><div id="cntrMenu"><h:commandButton id="cntrBtn1"onclick="createIFrameHTML();return false;"></h:commandButton><h:commandButton id="cntrBtn2"onclick="removeElement();return false;"></h:commandButton>
<div id="iFrameContainer"><!-- 将通过 createIFrameHTML() 生成 iframe -->
</h:form></f:view>