从 iFrame 卸载/删除内容 [英] Unloading/Removing content from an iFrame

查看:35
本文介绍了从 iFrame 卸载/删除内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何要卸载已加载到 iframe 中的页面?如果可能,我不想将 iframe src 更改为空白页面.我基本上是在寻找可以做这样的事情的东西 $('#frameID').attr("src",""); 除了代码似乎没有清除以前加载的页面.

Is there anyway to unload a page that has been loaded inside an iframe? I do not want to change the iframe src to a blank page if possible. I am basically looking for something that will do something like this $('#frameID').attr("src",""); except that code does not seem to clear the previously loaded page.

是否有我可以调用的 "unload" 函数,该函数将重置 iframe,使其内部没有加载任何内容?

Is there a "unload" function that I can call which will reset the iframe so that it does not have any content loaded inside?

推荐答案

其他解决方案使用 innerHTML,这在 XHTML 中并不总是有效.他们也只清除 document.body( 中的任何内容仍然存在).这是一个使用 DOM 的解决方案:

The other solutions use innerHTML, which won't always work in XHTML. They also only clear document.body (anything in the <head> is still present). Here is a solution that uses the DOM:

var frame = document.getElementById("myFrame"),
frameDoc = frame.contentDocument || frame.contentWindow.document;
frameDoc.removeChild(frameDoc.documentElement);

此解决方案使用 innerHTML:

var frame = document.getElementById("myFrame"),
frameDoc = frame.contentDocument || frame.contentWindow.document;
frameDoc.documentElement.innerHTML = "";

这篇关于从 iFrame 卸载/删除内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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