Skip to content Skip to sidebar Skip to footer

Get The Percentage Of The Page Load Using Javascript?

I'm writing an iphone application and need to show a progress bar that shows the loading progress of a web page. I want to insert a JS function to this page and once I call it, it

Solution 1:

No, it's not possible. You can emulate it by breaking up your page to small pieces and load it one by one with ajax requests but I don't think it is worth the trouble.

Another idea is to put little pieces of script like

<script>percentage += 10; updateProgressBar();</script>

through your page. That script will be executed the second browser loads (or parses) it so you will be able to estimate the progress.

Solution 2:

I don't think it is possible using Javascript, and unless the page is VERY big, I don't see why you'd need this. If you have lots of images on the page, this may be possible to tell how many of them are fully loaded.

Edit: I found this, that looks like want you want to do.

Edit 2 : And this answer on SO.

Solution 3:

How do you know what percentage of the HTML is loaded by Safari? Javascript from what I know of 1.7 can never be aware of that. If it did you would have far more sophisticated loaders for Gmail and the wealth of Google apps. You can do very crude estimations by injecting scripts and elements into the DOM programatically but it's a lot of effort for not much gain.

The best you can hope for is an animated GIF that runs for how long you'd estimate the page to load in a worst case scenario. Or the easier solution is to just use a throbber, hour glass or barber's pole.

Solution 4:

<html><head></head><body><scripttype="text/javascript"type="javascript">var percent=0;

functioncurpercent(){
    //TODO : show percent : $("#lblpercent").html(percent + "%");if (percent <=100) {
        curpercent();
    }

}

curpercent(); //call curpercent function when page download this line, coz, browser always download your page line by line.</script>

text body 1
<scripttype="text/javascript"type="javascript">
percent=10;
</script>

text body 2
<scripttype="text/javascript"type="javascript">
percent=20;
</script>

...

text body 10
<scripttype="text/javascript"type="javascript">
percent=100;
</script></body></html>

Post a Comment for "Get The Percentage Of The Page Load Using Javascript?"