以下のコードのcoutUp functionをhtmlの途中に埋め込むことで、そのhtmlページの読み込みの進捗状況を表示することができます。(こういう方法がいいかどうかはわかりませんが。)
function ProgressBar(id)
{
this.div = setProgressDIV(id);
this.init = init;
this.countUp = countUp;
var progress;
function setProgressDIV(id)
{
if(!id){
id = "_progress"+(new Date()).getTime();
var creprgDIV = document.createElement("DIV") ;
this.div = document.body.appendChild(creprgDIV) ;
this.div.setAttribute("id",id) ;
this.div.style.position = "relative";
this.div.style.top = "0px";
this.div.style.left = "0px";
this.div.style.width = "0px";
this.div.style.height = "0px";
} else {
this.div = document.getElementById(id)
}
this.div.style.color = 'blue' ;
this.div.style.margin = '0px' ;
this.div.style.padding = '4px';
this.div.prog_bar= '|';
this.div.prog_count =0;
this.div.prog_count_max =50;
this.div.prog_array= [];
return this.div
}
function init(arg){
this.div.innerHTML = '' ;
this.div.count =0;
this.div.barcount = 0.001;
this.div.prog_count_max = arg;
this.div.style.height ="12px";
this.div.style.width ="auto";
}
function countUp(){
if(this.div.count >= this.div.prog_count_max){
this.div.innerHTML = 'Load completed.';
}
else{
this.div.count++;
this.div.barcount += 10.0/this.div.prog_count_max;
while(this.div.barcount >= 1.0){
this.div.barcount = this.div.barcount - 1.0;
this.div.innerHTML += this.div.prog_bar;
}
}
}
return this;
}
function setUp(arg) {
progress = new ProgressBar('nowloading');
progress.init(arg);
}
function countUp(){
progress.countUp();
}
コメント