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

101
Visualizações
Running a script added after the page has loaded

I need to add the pages later for my project, but after adding the script tag at the bottom is not executed.

Main

const fetch = (url, call) => {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
         call(xhttp);
      }
  };
  xhttp.open("GET", url, true);
  xhttp.send();
}

const UpdatePage = page_name => {
  fetch(`/app/${page_name}`, (data => {
    App.innerHTML = data.responseText;
  }))
}

Code of new page

<div>
    <%= showId %>
</div>

<script>console.log("Welcome to somewhere")</script>

Page loads sucessfuly but the javascript not be executed. How i can execute the script tag on new page added?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I didn't really understand your question. From what I did though you want to run the script after the page has loaded.

For that you can use the defer tag

<script src="script.js" defer></script>

Read this MDN article for more info.

about 4 years ago · Juan Pablo Isaza Relatório

0

You must call the function

fetch();
UpdatePage();

Before doing this, you must call your file js in the ejs file

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