PDA

View Full Version : Displaying and refreshing a message while JavaScript code is executing



muuppal
08-04-2006, 11:34 PM
I have javaScript code that runs at onload event of the html page. This JavaScript code take few seconds to finnish. I would like to display message to my user such as 'Please wait while page is build' and hide this message once the JavaScript code runs complete.

How can i acheive that. Thanks for your help.

M. Uppal

Twey
08-05-2006, 12:25 AM
A nice effect is to put the rest of the page in "shadow":
var b = document.createElement("div"),
c = document.createElement("div");
c.style.position = b.style.position = "absolute";
c.style.top = c.style.left = "0";
c.style.height = c.style.width = "100%";
c.style.backgroundColor = "black";
c.style.filter = "alpha(Opacity=" + Math.floor((c.style.opacity = c.style.MozOpacity = c.style.KhtmlOpacity = "0.5") * 100) + ")";
b.style.top = b.style.left = "45%";
b.style.fontSize = "300%";
b.style.border = "2px solid red";
b.style.backgroundColor = "white";
b.appendChild(document.createTextNode("Please be patient while the document is loading."));
document.body.appendChild(c);
document.body.appendChild(b);

// long slow code goes here

document.body.removeChild(c);
document.body.removeChild(b);
c = b = null;