473,320 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,320 developers and data experts.

Javascript Loading Mask

eragon
431 256MB
JavaScript Loading Mask

Requirements: Little knowledge in JavaScript and some HTML. JavaScript enabled browser.
Applications: Useful for all those pages that load slow, and in sections, so instead of watching the page load in sections.


Put this in your <head>:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function overlay() {
  3. elem = document.getElementById("overlay");
  4.  elem.style.visibility="hidden";
  5. elem = document.getElementById("bodydiv");
  6.  elem.style.visibility="visible"; 
  7.  }
  8. </script>


Make your <body> tag look like this:
Expand|Select|Wrap|Line Numbers
  1. <body onLoad="overlay()">


Inside your <body>, at the top of everything, put this:
Expand|Select|Wrap|Line Numbers
  1. <div id="overlay" style="width:100%; height:100%; position: absolute; background-color:#000000;">
  2.     <table><tr><td valign="center" height="100%" width="100%">
  3.         <div align="center" style="border: 1px solid black; background-color:#ffffff; width:50%;">
  4.         <h3>Loading... Please Wait.</h3>
  5.         </div>
  6.     </td></tr></table>
  7. </div>
  8. <div id="bodydiv" style="visibility:hidden;">
  9.     ... (your current page body) ...<br />
  10.     ... (Which should be long..) ...<br />
  11.     ... (because it has to load) ...<br />
  12.     ... (so yeah.. this is body) ...
  13. </div>


So all together you get:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Loading Screen</title>
  4. <script type="text/javascript">
  5. function overlay() {
  6. elem = document.getElementById("overlay");
  7.  elem.style.visibility="hidden";
  8. elem = document.getElementById("bodydiv");
  9.  elem.style.visibility="visible"; 
  10.  }
  11. </script>
  12. </head>
  13. <body onLoad="overlay()">
  14.  
  15. <div id="overlay" style="width:100%; height:100%; position: absolute; background-color:#000000;">
  16.     <table><tr><td valign="center" height="100%" width="100%">
  17.         <div align="center" style="border: 1px solid black; background-color:#ffffff; width:50%;">
  18.         <h3>Loading... Please Wait.</h3>
  19.         </div>
  20.     </td></tr></table>
  21. </div>
  22. <div id="bodydiv" style="visibility:hidden;">
  23.     ... (your current page body) ...<br />
  24.     ... (Which should be long..) ...<br />
  25.     ... (because it has to load) ...<br />
  26.     ... (so yeah.. this is body) ...
  27. </div>
  28.  
  29. </body>
  30. </html>


And you have a pleasant loading message. You may edit the content (div styles, etc.) but the JavaScript must remain as is, unless you know what you are doing. This is really a simple script, but it is there for those that want it.

Sincerely,
Eragon
Dec 1 '07 #1
13 37835
acoder
16,027 Expert Mod 8TB
Are you sure you've got the background color correct - o or 0?

Remember, Java != JavaScript.

Otherwise, I'm sure people will find this useful.
Dec 3 '07 #2
eragon
431 256MB
Background color fix: #000000

and thats all i presume. Please check for compatibility...

thank you :)
Dec 4 '07 #3
acoder
16,027 Expert Mod 8TB
Background color fix: #000000

and thats all i presume. Please check for compatibility...
Fixed. I'll check it later.
Dec 5 '07 #4
acoder
16,027 Expert Mod 8TB
There was a mistake in the full version of the code in the body onload (line 13). You forgot the parentheses/brackets. I've added them for you.

This seems to work well, but you should consider changing the colors and font - black and white is a bit boring!
Jan 1 '08 #5
eragon
431 256MB
There was a mistake in the full version of the code in the body onload (line 13). You forgot the parentheses/brackets. I've added them for you.

This seems to work well, but you should consider changing the colors and font - black and white is a bit boring!
thanks. This code is user customizable. They can change the colors at will.
Jan 2 '08 #6
acoder
16,027 Expert Mod 8TB
thanks. This code is user customizable. They can change the colors at will.
Of course, but rather than changing inline, it should be customizable through JavaScript since the overlay should not display if JavaScript is not enabled. In fact, you should consider a drop-in script which would involve the use of document.write after the body tag.
Jan 2 '08 #7
eragon
431 256MB
Of course, but rather than changing inline, it should be customizable through JavaScript since the overlay should not display if JavaScript is not enabled. In fact, you should consider a drop-in script which would involve the use of document.write after the body tag.
good idea.... ill change that and post another code. Because with this one, if the user doesn't have javascript, your just going to have an infinitely loading page.

ill post another version when i get done with a few things.
Jan 3 '08 #8
Hi, this does not seem to work in IE8, could anyone fix this?
LE: I added Adsense code during loading process and after the page is loaded adsense sticks out, does not disappear.
LE2: Adsense issue fixed :D
Now I only need to make it work in IE8.
Mar 15 '09 #9
acoder
16,027 Expert Mod 8TB
What happens in IE8? Have you tried other versions of IE?

You may want to post in the forum instead of here to get a better response.
Mar 19 '09 #10
@acoder
In Mozilla, Safari and Chrome everything looks perfect but in IE(tried 6,7 and 8) the preloader is loading in the right of the page, not in the middle, maybe is because position:absolute, i don't know... can anyone help?
Mar 27 '09 #11
acoder
16,027 Expert Mod 8TB
Ah right, that's more a CSS problem. Here's one way you could do it. You may also find this useful. Failing that, ask in the HTML/CSS forum.
Mar 31 '09 #12
eragon
431 256MB
Two years it took.

But alas, i have returned.

And by the way, i have a better code.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Loading Screen</title>
  4. <script type="text/javascript">
  5.  
  6.     //Hide the body. See, if you have javascript, it would hide, otherwise, it's visible.
  7.     elem3 = document.getElementById("bodydiv");
  8.     elem3.style.visibility="hidden";
  9.  
  10.     //Show the loading page. Same as above.
  11.     elem4 = document.getElementById("overlay");
  12.     elem4.style.visibility="visible";
  13.  
  14.     function overlay() {
  15.         elem = document.getElementById("overlay");
  16.         elem.style.visibility="hidden";
  17.         elem2 = document.getElementById("bodydiv");
  18.         elem2.style.visibility="visible"; 
  19.     }
  20. </script>
  21. <style>
  22.  
  23.     #overlay {
  24.         width: 100%;
  25.         height: 100%;
  26.         position: absolute;
  27.         visibility: hidden;
  28.  
  29.         /*Background information for the preloading mask:*/
  30.         background-color:#000000;
  31.  
  32.         /*Font color and options:*/
  33.         color:#CCCCCC;
  34.         font-family:Georgia, "Times New Roman", Times, serif;
  35.         font-size:16px;
  36.     }
  37.  
  38. </style>
  39. </head>
  40. <body onLoad="overlay()">
  41. <div id="overlay">
  42.     <table><tr><td valign="center" height="100%" width="100%">
  43.         <div align="center">
  44.             Loading... Please Wait.<!--You can put pretty much whatever here.-->
  45.         </div>
  46.     </td></tr></table>
  47. </div>
  48.  
  49. <div id="bodydiv" style="visibility:visible;">
  50.  
  51. <!-- YOUR BODY CONTENT WOULD GO HERE -->
  52.  
  53. </div>
  54. </body>
  55. </html>
Jul 7 '09 #13
acoder
16,027 Expert Mod 8TB
That wouldn't work because on line 7, bodydiv wouldn't have been defined yet.
Jul 7 '09 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Robbie | last post by:
I have a simple script that changes the src and height and width of a <img>. But when I load the image it changes it size first, streching or shrinking the previous image, before changing the...
5
by: joaopedrogoncalves | last post by:
Hi, I want to load an external javascript file, get its results and stick them inside a <div> block. I also want to do this in several places on a web page. This way the browser doesn't have...
3
by: Martin | last post by:
I need a Javascript function that can do a Bit Test on a numeric value. IOW, given a numeric value (a 16 bit integer value) and a bit number, tell me whether that bit is 1 or 0. I have no idea...
6
by: Venkatesh | last post by:
Hello All, I have couple of doubts regarding the concept of on-demand javascript loading using javascript code. I could see on the net different techniques for achieving this - techniques like:...
1
by: mangust404 | last post by:
Hi, i suppose this project could be helpfull to people who make a web-applications with a horde of javascript-includings. This project is Prototypejs-based and it consists from prototype.js itself...
20
RMWChaos
by: RMWChaos | last post by:
Currently testing in: WinVista / IE7 I have been working on getting xmlhttprequest going for weeks now. I have finally gotten a semi-working script going. Pulling up text or xml files works great...
3
by: sandeep kumar shah | last post by:
I am facing one problem on loading the xml file The code is 1. XML file //attribute.xml <?xml version="1.0" encoding="UTF-8"?> <person> <name>sandeep</name> <address state="Goa �D;...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.