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

95
Views
Reloading Page using javascript but updating original body HTML

Is it possible to reload a page in javascript but update the original HTML defined in the body tag? An example is below:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
</head>
<script language="javascript" type="text/javascript">
    window.onload = function(){  
        document.getElementById("button").addEventListener('click', () => {
        document.body.innerHTML = `<h1> ${Math.floor(Math.random() * 99999)}`;
        location.reload()
    });
    }
</script>
<body>
    <h1>Hehe</h1>
    <button id = "button">Reset</button>
</body>
</html>

The above will change the original body tag to a random number when "button" is clicked on and as expected, the body tag will revert back to its original state after refreshing (though it will briefly show the updated state before refreshing).

Is it possible to have the body html remain different even after "refresh" is called?

about 4 years ago · Juan Pablo Isaza
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!