/    Sign up×
Community /Pin to ProfileBookmark

How can i dectect what percentage of the page has loaded in
Internet explorer so i can create a loading meter in JS?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@HaganeNoKokoroNov 01.2004 — Something like this maybe?<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 STRICT//EN" "http://www.w3.org/TR/HTML401/strict.dtd">
<html>
<head>
<script type="text/javascript">
var totalBytes=150000;
var loadedBytes=0;
var statusBarWidth=200;
var statusBarHeight=20;
function displayStatusBar() {
document.write("<div style='position:relative;width:"+statusBarWidth+"px;height:"+statusBarHeight+"px;border:solid #aabbff 1px'>");
document.write("<img id='statusBar' src='images/bar.bmp' style='width:1px;height:"+statusBarHeight+"px'></div>");
}
function updateStatusBar(nBytes) {
loadedBytes+=nBytes;
var currentWidth=Math.round(loadedBytes/totalBytes*statusBarWidth);
document.getElementById("statusBar").style.width=currentWidth+"px";
}
displayStatusBar(); //write the status bar at the top of the page
</script>
</head>
<body>
<div id="main">
<img src="images/bm1.jpg" onload="updateStatusBar(50000);">
<img src="images/bm2.jpg" onload="updateStatusBar(50000);">
<img src="images/bm3.jpg" onload="updateStatusBar(50000);">
</div>
</body>
</html>
It's not a very good way to do it. Basically, you have to tell it how much to add to the currently loaded amount whenever an image loads, and you have to know the total beforehand. In the example, each image added 50000 to the loaded total, which I of course set as 150000. so after each image loads, the status bar jumps by 1/3. If you have access to server-side code, you could use that to fill in accurate file size values for the images and total.

I really have no idea if there is a way to just access the percentage of the page loaded. It doesn't seem likely, since it would have to know how much the total was, including images etc, and I think browsers work more by reading the html, then fetching whatever else is needed in separate requests.
Copy linkTweet thisAlerts:
@Warren86Nov 01.2004 — I don't know if you will find this to be useful, but the following is an ActiveX progress bar. Clicking on it will increase the "progress." The min and max values are 0 and 100, respectively.

All you need to do is create a function that modifies the ProgressBar1.value. The onclick code is only for the purpose of demonstrating it.

<HTML>

<HEAD>

<Script Language=JavaScript>

var isProgress = 0;

function updateProgress(){

isProgress = isProgress+10;

ProgressBar1.value=isProgress;

}

</Script>

<SCRIPT LANGUAGE="VBScript">

Sub ProgressBar1_Click()

updateProgress()

end sub

</SCRIPT>

</HEAD>

<BODY>

<OBJECT ID="ProgressBar1" WIDTH=123 HEIGHT=20

CLASSID="CLSID:0713E8D2-850A-101B-AFC0-4210102A8DA7">

<PARAM NAME="_ExtentX" VALUE="2646">

<PARAM NAME="_
ExtentY" VALUE="1323">

<PARAM NAME="_Version" VALUE="327682">

<PARAM NAME="Appearance" VALUE="1">

</OBJECT>

</BODY>

</HTML>
×

Success!

Help @ck_net_2004 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...