Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A page load message for my website anyone?

Status
Not open for further replies.

PrayingMantus

Vendor
Aug 8, 2003
40
AU
Does anyone know of a code that I can use to display a “page loading....” message on my website's home page? Problem with all the codes I've found is that they display the message until the page is fully loaded. Idealy it would be nice for the message to disapear as soon as the page is visable to the viewer. Any help would be so appreciated I spent all day yeasterday looking for code but got nowhere.
 
the concept is pretty simple,
Code:
<html>
<div id="Loading">Loading...</div>
<input type="button" value="Remove Loading" onclick="document.getElementById('Loading').innerText=''">
</html>

the button will make the loading text to disappear, u can use this concept to create ur loading thing????

Known is handfull, Unknown is worldfull
 
Thanks vbkris, but I was after something a little more complex. I need a code to be able to show the message "Loading..." Either text or animated gif (I would perefer the gif option). The code must be able to show the text or gif before any other content opens and then disapear once the page content appears on the screen. The problem I have found with most javascripts is that the message will appear untill page is fully loaded which does not allow the viewer to use the page untill its fully loaded.

Any help would be great! Thanks guys.
 
The following should run until the page is fully loaded but NOT interfere with using the page, as you mentioned above:

Code:
<html>
<head>
<script>
var count = 1; //# of dots following 'Loading'
var interval = 5; //# of dots allowed following 'Loading'
var to; //timeout object

[b]//start message even before document has loaded
loading();[/b]

function loading()
{
  if(count == interval)
  {
   //reset to one dot
   window.status = "Loading.";
   count = 1;
  }//end if
  else
  {
   //add a dot
   count++;
   window.status += ".";
  }//end else

  //set thread to run independent of page loading
  to = setTimeout("loading()",1000); 
}//end loading()

function quitTimeout()
{
 //interrupt the 'Loading.....' message thread
 clearTimeout(to);
 window.status = "Done.";
}//end quitTimeout()
</script>
</head>
<body [b]onload='quitTimeout()'[/b]>
Your HTML here.
</body>
</html>

This works for me in IE6. 'hope it helps.

--Dave
 
Thanks Dave for your code, it doesn't work for me although the code looks good. Nothing is displaying as the page loads. Did I have to edit anything? I put the head section (minus head tags) in my head section, & body (minus body tags) into my body section. Have I missed something? Thanks again for your help.
 
What browser are you using?

Maybe window.status doesn't work.

Pardon me if the answer to this is obvious, but do you know that "window.status" puts the message inside the bottom border of the browser window?

Do you have the status bar ON? If you're using IE, drop the VIEW menu and click on 'Status Bar.' That's where my code sends the message. This is the safest place to send it because the code launches before the BODY tag is even reached. If you were to try to send the 'Loading.....' message to the innerHTML of a SPAN tag, for example, it's possible you'll get an error because the SPAN tag hasn't been drawn yet.

Check all that and reply. Good luck.

--Dave
 
hahaha, yeah sorry for my ignorance Dave! Yeah that code does work fine, no I didn't know about "window.status" I am not a programer but just a humble "cut 'n' paste" javascript boy :) I really was wanting the message to be in the middle of the screen, similar to that of some of the "flash type" loading presentations. Although I do like the status bar code that you gave, but I think that not too many people look at the status bar. Any others up your sleeve?
 
A slight variation might be the following...

Code:
<html>
<head>
<script>
var count = 1; //# of dots following 'Loading'
var interval = 5; //# of dots allowed following 'Loading'
var to; //timeout object
[b]var ready = false;[/b]

//start message even before document has loaded
loading();

function loading()
{
 [b]if(ready)[/b]
 {
  if(count == interval)
  {
   //reset to one dot
   [b]loadingSpan.innerHTML = "Loading.";[/b]
   count = 1;
  }//end if
  else
  {
   //add a dot
   count++;
   [b]loadingSpan.innerHTML += ".";[/b]
  }//end else
 [b]}//end if[/b]

 //set thread to run independent of page loading
 to = setTimeout("loading()",1000); 
}//end loading()

function quitTimeout()
{
 //interrupt the 'Loading.....' message thread
 clearTimeout(to);
 [b]loadingSpan.innerHTML = ""; //clear it out
 ready = false; //this line not really needed[/b]
}//end quitTimeout()
</script>
</head>
<body onload='quitTimeout()'>
[b]<h4><span id='loadingSpan'></span></h4>
<script>
ready = true;
</script>
<br />[/b]

The rest of your HTML here.
</body>
</html>

This way, the page, when drawing, tells the javascript function when the HTML tag that will bear the Loading.... message is drawn and you don't run the risk of that error I mentioned in a previous post.

Let me know if that helps.

Good luck!

--Dave
 
WOW I love it, only is it possible to get the message in the center of the screen? & can I change the font/size (if so how/where). Also it pushes the my html (title bar pic) down the page a bit. I was thinking if the code needs its own space on the page to display the message maybe I can put it between some of the text in the middle of the page (where there is already a space). But yeah just knowing how to do it :). thanks so much your codes work great!
 
Okay, here're some modifications:

Code:
<html>
<head>
<script>
var count = 1; //# of dots following 'Loading'
var interval = 5; //# of dots allowed following 'Loading'
var to; //timeout object
var ready = false;

//start message even before document has loaded
loading();

function loading()
{
 if(ready)
 {
  if(count == interval)
  {
   //reset to one dot
[b]   loadingSpan.innerHTML = "Loading";
    dotSpan.innerHTML = ".";[/b]
   count = 1;
  }//end if
  else
  {
   //add a dot
   count++;
   [b]loadingSpan.innerHTML = "Loading";
   dotSpan.innerHTML += ".";[/b]
  }//end else
 }//end if

 //set thread to run independent of page loading
 to = setTimeout("loading()",1000); 
}//end loading()

function quitTimeout()
{
 //interrupt the 'Loading.....' message thread
 clearTimeout(to);
 loadingSpan.innerHTML = ""; //clear it out
[b] dotSpan.innerHTML = ""; //clear it out
 loadingTable.style.visibility = 'hidden';
 loadingTable.style.display = 'none';[/b]
 ready = false; //this line not really needed
}//end quitTimeout()
</script>
</head>
<body onload='quitTimeout()'>
[b]
<!-- NOTE:  the problem with just centering the message using CENTER tags would be that as the dots (...) keep getting added to the message, it keeps re-centering.  With the table method, below, the message stays put.  Check it out. -->
<span id='loadingTable'>
<table align='center' width='100%'>
<tr>
<td width='50%' align='right'>
<span id='loadingSpan'>&nbsp;</span>
</td>
<td width='50%' align='left'>
<span id='dotSpan'>&nbsp;</span>
</td>
</tr>
</table>
</span>
[/b]
<script>
ready = true;
</script>
<br />

The rest of your HTML here.
</body>
</html>

The loading message should now be centered. When it's done, the space it takes up disappears and everything else shifts up. This shift might be disconcerting to the user, but try it out and see how it works for you.

To play with the font, you can create a style class and assign it to the loadingSpan tag (e.g., class='loadingStyle'). Check out for styles you can apply to the SPAN tag.

--Dave
 
OK maybe you'd better have a look for yourself: (TEST1, WITHOUT ABOVE CODE)
(TEST2, WITH ABOVE CODE).
I have added the large bitmap down the bottom of the pages to increase loading time. Also maybe you could help me to know how I can get the menu on the left to load quicker, for some reason it loads last. Thanks so much for your help.
 
The loading message looks like it's working fine. You might want to put <B> tags around it, or, as I said, add one of your style classes as the CLASS attribute of your loadingSpan SPAN tag.

It's a little hard (and time-consuming) to get into all the code on that page, but something I noticed right away that might be giving you a little trouble is that you have two functions named Go. That might cause some frustration for the page as it's drawing.

Good luck!

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top