Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

96
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda