[英]Firefox flickers upon document update
I have an iframe like this: 我有一个这样的iframe:
<iframe id="htmlRender">
</iframe>
And I have a JS snippet to update the iframe's content: 我有一个JS代码段来更新iframe的内容:
function renderHtml(htmlString) {
var iframe = document.getElementById('htmlRender');
var doc;
if (iframe.contentDocument) {
doc = iframe.contentDocument;
}
else if (iframe.contentWindow) {
doc = iframe.contentWindow.document;
}
else {
doc = iframe.document;
}
doc.body.innerHTML = '';
doc.open();
doc.writeln(htmlString);
doc.close();
}
When I call renderHtml
, the content updates correctly. 当我调用renderHtml
,内容会正确更新。 However, I see a flicker in Firefox, which causes a bad UX. 但是,我在Firefox中看到闪烁,这会导致错误的UX。 I am not seeing other browsers having the same issue. 我没有看到其他浏览器有同样的问题。
How can I fix this flicker issue in Firefox? 如何解决Firefox中的闪烁问题? Thanks! 谢谢!
You don't need to do the open, writeLn, close stuff. 您不需要执行打开,writeLn和关闭操作。 Just do the innerHTML thing. 只是做innerHTML事情。
Like this: 像这样:
function renderHtml(htmlString) {
var iframe = document.getElementById('htmlRender');
var doc = iframe.contentDocument ||
iframe.contentWindow.document ||
iframe.document;
doc.body.innerHTML = htmlString;
}
renderHtml('<strong>hello</strong');
Created this jsfiddle example: 创建了这个jsfiddle示例:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.