...

View Full Version : Loading page script?



AshleyQuick
11-11-2004, 04:39 PM
Is there a way to displaying "Loading page, please wait" while the entire page is loading? I've found some page preloaders however all of them show "Loading page, please wait" on a blank page until the page is loaded. Is it possible to show this message on a page and have the content load around it?

Ash

jbot
11-11-2004, 04:45 PM
yes, that's easy ...

just put an element at the very beginning of the document, just after the body tag, the text of which is your loading message. then, after the body tag insert a script which goes something like this:

<script type="text/javascript">

window.onload
{
document.getElementsByTagName("body")[0].removeChild(document.getElementById("id_of_loading_message_tag"));
}

</script>

AshleyQuick
11-11-2004, 05:04 PM
Hmm, here's what I have thus far:


</head>

<body>

<script type="text/javascript">

window.onload
{
document.getElementsByTagName("body")[0].removeChild(document.getElementById("loadingMSG"));
}

</script>

<div id="loadingMSG" style="position:absolute; left:100px; top:4px">
Loading page, please wait...</div>

The message does not disappear. What am I doing wrong?

Ash

jbot
11-11-2004, 05:38 PM
</head>

<body>

<script type="text/javascript">

window.onload
{
document.getElementsByTagName("body")[0].removeChild(document.getElementById("loadingMSG"));
}

</script>

<div id="loadingMSG" style="position:absolute; left:100px; top:4px">
Loading page, please wait...</div>


do it this way:


</head>

<body>

<div id="loadingMSG" style="position:absolute; left:100px; top:4px">
Loading page, please wait...</div>

</body>
<script type="text/javascript">

window.onload
{
document.getElementsByTagName("body")[0].removeChild(document.getElementById("loadingMSG"));
}

</script>
</html>

AshleyQuick
11-11-2004, 06:00 PM
Like a charm! Thank you!

Ash

AshleyQuick
11-12-2004, 07:31 AM
Can this be modified to use in a page that contains an iframe so that the iframe content must load as well before the message disappears?

jbot
11-12-2004, 09:43 AM
hmmmm, yes, prolly, with a little massaging.

in the iframe, put this at the end of the document:


<script>
window.onload
{
top.checkIfLoaded();
}
</script>

then in main page, put this at the end of the document:


<script>
window.onload
{
checkIfLoaded();
}
</script>

then in main page, put this in the head of the document:


<script type="text/javascript">

var pageCounter=0, totalPages=2;

function checkIfLoaded()
{
pageCounter++;

if (pageCounter==totalPages) document.getElementsByTagName("body")[0].removeChild(document.getElementById("loadingMSG"));
}

</script>

AshleyQuick
11-12-2004, 06:02 PM
Nice work! Thank you immensely! :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum