Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
190
rated 0 times [  192] [ 2]  / answers: 1 / hits: 117516  / 14 Years ago, thu, september 2, 2010, 12:00:00

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)?


More From » html

 Answers
6

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 */

}


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



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



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


show the DIV directly after :



 <script type=text/javascript>
document.getElementById(hideAll).style.display = block;
</script>


and hide it onload:



 window.onload = function() 
{ document.getElementById(hideAll).style.display = none; }


or using jQuery



 $(window).load(function() {  document.getElementById(hideAll).style.display = none; });


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.


[#95728] Monday, August 30, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jazminkyrap

Total Points: 631
Total Questions: 89
Total Answers: 109

Location: Finland
Member since Fri, Oct 21, 2022
2 Years ago
;