Solved

Hding content until after load

Posted on 2004-09-28
6
1,296 Views
Last Modified: 2012-06-21
For a project I am currently working on, we are using dynamic html and javascript to display content based on what menu link the user clicks on.  I've noticed one little nuance though that I would like to fix.

In the body's onload event, we call our javascript function to hide all the content cells except for the welcome page.  The problem is that with network lag, all the content for the page shows up initially until the page is finished loading and the onload event fires, hiding the data we dont want to show.  Is there a way to prevent this?  We would like everything to be hidden initially, and then when the onload fires, we can unhide the welcome page or something to that effect.  Any ideas?
0
Comment
Question by:porkVT
6 Comments
 
LVL 13

Accepted Solution

by:
cLFlaVA earned 250 total points
ID: 12169317
Have you looked into the setTimeout() function?

You could have everything initially hidden, and on the body's onload event, you could call a function that will unhide everything...

<head>
<script language="JavaScript">
<!--
function unHideStuff() {
    for (var i = 0; i < 5; i++) {
        document.getElementById('the_div_' + i.toString()).style.display = 'block';
    }
}
-->
</script>
</head>

<body onload="return unHideStuff();">
<div id="the_div_0" style="display: none;">stuff...</div>
<div id="the_div_1" style="display: none;">stuff...</div>
<div id="the_div_2" style="display: none;">stuff...</div>
<div id="the_div_3" style="display: none;">stuff...</div>
<div id="the_div_4" style="display: none;">stuff...</div>
0
 
LVL 13

Expert Comment

by:cLFlaVA
ID: 12169320
By the way -- the reference to setTimeout() was an initial idea I had, then abandoned.  Sorry to confuse you :)
0
 
LVL 4

Expert Comment

by:aratani
ID: 12169571
Why dont you hide all the elements before and then unhide it as needed by using style = "display: none;"? That would make more sense if you don't want the elements showing up anyway?

AJ
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 12170286
<style>
body * {display:none;}
body.loaded * {display:inherit;}
</style>
<body onload="this.className='loaded';">
stuff
</body>

-r-
0
 
LVL 19

Expert Comment

by:dakyd
ID: 15646175
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:

ACCEPT cLFlaVA  -- http://Q_21147802.html#12169317

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

dakyd
EE Cleanup Volunteer
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question