473,549 Members | 2,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript Loading Mask

eragon
431 Contributor
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 37880
acoder
16,027 Recognized Expert Moderator MVP
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 Contributor
Background color fix: #000000

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

thank you :)
Dec 4 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
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 Recognized Expert Moderator MVP
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 Contributor
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 Recognized Expert Moderator MVP
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 Contributor
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
katalin
2 New Member
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 Recognized Expert Moderator MVP
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

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

Similar topics

1
1539
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 image. This is because the picture hasn't loaded yet. How can I have it so that it waits till the image is loaded before changing the height width and...
5
5189
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 to wait for the external resource to load to show up the page, thus giving a perceiving faster load time for the user.
3
3044
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 how to do this. Help?
6
2752
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. document.write("<script src= language='JavaScript'></script>); 2. sc = document.createElement("<script>"); sc.setAttribute("src", ); and...
1
1207
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 and script.aculo.us. http://jear.sourceforge.net Thanks for your attention.
20
4009
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 and populates into the webpage; however, executing javascript has a few problems: 1. Opens on a blank page, but not a new page. It appears to...
3
2834
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; Panjim" distt="madgaon"/>
0
7524
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7451
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7720
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7960
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7475
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5372
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1061
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
766
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.