Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
Get the loading progress in JavaScript

So I'm thinking about making a gravatar link getter and I would like to add a loading screen but I don't know how to get loading progress with JavaScript when loading HTML and CSS assets

let loadingpercent = percent();

function LoadProj()
{
  document.write("Hold On, your request is loading.<br> " + loadingpercent);
}

function percent()
{
    //Code Goes here
    return NaN;
}
<input type="button" onClick="LoadProj()" value="LoadMe">

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can store the percent in a variable and the interval at which the progress should increment in another (in ms).

Then, in your LoadProj function, increment the percent and set the innerHTML of the body to the right value. Check if the percent is not 100. If it is not, we can use setTimeout to call LoadProj again with a delay, in our case, loadInterval. If it is, you know that it is finished loading, and you can handle it accordingly.

var percent = 0;
var loadInterval = 100;

function LoadProj() {
  percent++;
  document.body.innerHTML = "Hold On, your request is loading. " + percent;
  if (percent != 100) {
    setTimeout(LoadProj, loadInterval)
  }else{
    //Finished loading! Your code here...
    console.log('Finished loading!')
  }
}
<input type="button" onClick="LoadProj()" value="LoadMe">

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!