加载完成后显示 HTML 页面 [英] display HTML page after loading complete

查看:47
本文介绍了加载完成后显示 HTML 页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法强制浏览器在页面的所有内容(如图像、脚本、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 */

 }

(请注意,position: fixed 在 IE6 中不起作用 - 我知道在该浏览器中没有确定的方法)

(Note that position: fixed won't work in IE6 - I know of no sure-fire way of doing this in that browser)

像这样添加 DIV(直接在开始的 body 标签之后):

Add the DIV like so (directly after the opening body tag):

<div style="display: none" id="hideAll">&nbsp;</div>

在 :

 <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 页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆