iframe的src设置为about:blank之后细节探讨_HTML/Xhtml_网页制作

WBOY
Release: 2016-05-16 16:40:21
Original
1967 people have browsed it

设置 iframe 的 src 为 'about:blank' 之后,不置为“about:blank”,内存不会释放掉。还必须用 iframe.document.write('');
这样才能将内容清空,但是这样处理之后任然会有500-1000K左右的内存残留,这就是ie6的iframe bug,动态创建的iframe总会耗费掉一些内存。

复制代码
代码如下:

function clearIframe(id){
var el = document.getElementById(id),
iframe = el.contentWindow;
if(el){
el.src = 'about:blank';
try{
iframe.document.write('');
iframe.document.clear();
}catch(e){};
//以上可以清除大部分的内存和文档节点记录数了
//最后删除掉这个 iframe 就哦咧。
document.body.removeChild(el);
} } clearIframe('iframe_id');
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!