Loading Bar until page loads completely using Javascript

This tutorial was requested by Sumit. In this tutorial I'm going to tell how to put up a loading screen until the page has loaded completely.
Here is the screenshot of loading screen :
The loading bar will fade out when loading is completed.
This code will work for all sites including Blogger Blogs, WordPress Blogs except Dynamic Views Template of Blogger (because it uses ajax loading).
You can change the image if you want. I have created an image of my own :
Ok. Now let's get down to the code. This code is pure Javascript, no jQuery because the site might be loading jQuery and we should have to show the loading bar before the loading of jQuery.
Here is the code. You have to place it just after <head>

 var subinsblog=document.createElement("div");
 var polu=99*99*99999999*999999999;
 subinsblog.style.background="black url(https://lh4.googleusercontent.com/-4WVJgCO93zc/UgpU2Y60CjI/AAAAAAAAC8E/R3XujnTjz3Y/s474/initializing.png) 50% 50% no-repeat";
}else if(document.getElementById('subinsblogldiv')!=null){
I would recomment you to not replace the variable names, because there might be an other variable like that and the code won't work.
If you want to change the Loading Image just change the

url in the variable subinsblog.style.background.
Well that's it for now. If you have any problems/suggestions/feedback, just say it out in the comment form below and Happy Independence Day to all Indians and Pakistanis.

Post a Comment