我有一个文件列表。当我点击它们时,内容显示在一个框架内。我遇到的问题是:当我打开一个文件并移动到下一个文件(如果文件的大小更大,加载需要一些时间),旧文件的内容仍然显示在iframe中。只要我点击下一个文件,我想清除iframe中的旧文件的内容,同时它正在加载我可以显示加载指示器。清除现有的iframe内容
要清除iframe中的内容,我尝试了一些方法,但无法成功。你能告诉我这个
我的HTML
<div id="result">
<div style="overflow: auto;" id="testIframeBox">
<iframe id="testiframe" name="testIframe" onload="">iFramenot supported</iframe></div>
</div>
我出现使用点击文件location.replace
window.frames['testIframe'].location.replace(URL+"&download=1&inline=1&resourceId="+resourceId+"&time=" + Date.now());
要清除内容:
if(document.getElementById('testiframe'))
{
var frame = document.getElementById("testIframe"),
frameDoc = frame.contentDocument || frame.contentWindow.document;
frameDoc.documentElement.innerHTML="";
}
此外,我试过在装入内容之前用装载指示器替换内容:
window.frames['testIframe'].location.replace('div class="loading-animation"></div>');
这与许多例子以前回答。 http://stackoverflow.com/questions/1785040/how-to-clear-the-content-of-an-iframe – Sswell410 2014-11-24 13:49:59