问题描述
有没有办法强制浏览器只有在所有的页面的内容被完全加载显示一个页面(如图片,脚本,CSS等)?
Is there a way to force the browser to display a page only after all of the page's contents are completely loaded (such as images, scripts, css, etc)?
推荐答案
做的是把一个 DIV
在身体下面的CSS最简单的事情:
The easiest thing to do is putting a div
with the following CSS in the body:
#hideAll
{
position: fixed;
left: 0px;
right: 0px;
top: 0px;
bottom: 0px;
background-color: white;
z-index: 99; /* Higher than anything else in the document */
}
(注意:的位置是:固定
将无法工作在IE6 - 我所知,没有在该浏览器这样做的安全可靠的方式)
(Note that position: fixed
won't work in IE6 - I know of no sure-fire way of doing this in that browser)
添加DIV像这样(直接开通后体
标记):
Add the DIV like so (directly after the opening body
tag):
<div style="display: none" id="hideAll"> </div>
显示DIV后直接:
show the DIV directly after :
<script type="text/javascript">
document.getElementById("hideAll").style.display = "block";
</script>
和隐藏的onload
:
window.onload = function()
{ document.getElementById("hideAll").style.display = "none"; }
或使用jQuery
$(window).load(function() { document.getElementById("hideAll").style.display = "none"; });
这种方法的优点是,它也将为谁关闭了JavaScript客户端。它的不应的造成任何闪烁或其他副作用,但没有测试它,我不能完全保证它的每一个浏览器在那里。
this approach has the advantage that it will also work for clients who have JavaScript turned off. It shouldn't cause any flickering or other side-effects, but not having tested it, I can't entirely guarantee it for every browser out there.
这篇关于加载完成后,显示HTML页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!