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

100
Views
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 answers
Answer question

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 Report

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 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!