【发布时间】:2014-07-16 17:13:19
【问题描述】:
我的网站中有一个 iframe,必须每秒重新加载(它只是重新加载简单的 HTML 以进行数据分析)。这会在每次重新加载时导致非常烦人的白色闪光。
我花了数小时研究试图移除这个闪光灯。这是我所拥有的(不起作用),它创建一个新的 iframe,将其添加到 DOM,然后删除旧的,有效地重新加载页面。但它仍然闪烁白色:
$( document ).ready(function() {
setInterval(function() {
var container = document.getElementById('bottom-frame-container');
var source = container.getElementsByTagName('iframe')[0];
var newFrame = document.createElement('iframe');
for (i = 0; i < source.attributes.length; i++) {
var attr = source.attributes[i];
newFrame.setAttribute(attr.name, attr.value);
}
newFrame.style.visibility = 'hidden';
newFrame.id = 'bottom-frame';
container.appendChild(newFrame);
newFrame.style.visibility = 'visible';
container.removeChild(container.getElementsByTagName('iframe')[0]);
}, 1000);
});
iframe 代码很简单:
<div id="bottom-frame-container">
<iframe id="bottom-frame" width="100%" height="60%" frameborder="0" allowTransparency="true" src="http://10.62.0.15/haproxy?stats">
</div>
我对这里的任何建议或替代方法完全持开放态度,我有点绝望了!
【问题讨论】:
-
iframe changeurl = function () { fade out iframe container - }-iframe.onload = function() { fadebackiniframecontainer }怎么样? (伪) -
Flash 是由于每秒删除和注入元素,你会弄乱文档流,这会让人迷失方向。在理想情况下,通过 Web 服务显示数据的 AJAX 会更理想...至少是您域中的页面吗?
-
@RobSedgwick 他还应该绝对将 iframe 放置在彼此之上。
-
真正奇怪的是你每秒都会重新加载整个页面。一定有更好的方法……(通常 AJAX 就是用来解决这种情况的)
标签: javascript jquery html iframe