我有一個文件列表。當我點擊它們時,內容顯示在一個框架內。我遇到的問題是:當我打開一個文件並移動到下一個文件(如果文件的大小更大,加載需要一些時間),舊文件的內容仍然顯示在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