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

156
Views
Cambie el script "src" por parámetro de URL y hágalo funcional

Estoy pensando si es posible hacer esto en un sitio web estático,
tengo el enlace de

 https://www.example.com?year=2022&week=05

y el HTML principal es

 <h4 style="color:#FFD700"><strong>TITLE</strong><br></h1> <h3 id="1testing"></h3> <h6 id="2testing"></h6> // skipped <script id="results" src="path/to/script/202205.txt"></script>

Ahora, quiero hacer que se actualice de acuerdo con el parámetro de URL, tengo un parámetro de URL (y actualizo el código anterior) por

 const queryString = window.location.search; console.log(queryString); const urlParams = new URLSearchParams(queryString); const yrs = urlParams.get('year') const wks = urlParams.get('week') console.log(yrs); console.log(wks); document.getElementById('results').src = "path/to/script/" + yrs + "/" + wks + ".txt"

Los archivos txt están en el formato de

 document.getElementById("date").innerHTML =// date "date"; // Number 1 document.getElementById("1testing").innerHTML =// 1testing "1testing"; document.getElementById("2testing").innerHTML =// 2testing "2testing"; //so on...

Sin embargo, el problema que tengo es que la etiqueta src se actualizó DESPUÉS de cargar y el contenido simplemente no se actualiza, posiblemente debido a que los scripts no están en orden, sin embargo, no tengo mucho conocimiento sobre esto, cualquiera podría ayudar con un solución en esto?

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

0

Creo que debería eliminar la etiqueta del script y volver a agregar la actualizada.

 let oldScriptTag = document.getElementById('results'); let newScriptTag = document.createElement('script'); newScriptTag.id = 'results'; newScriptTag.src = 'path/to/script/' + yrs + '/' + wks + '.js'; newScriptTag.textContent = '//script'; var body = document.getElementsByTagName('body')[0]; oldScriptTag.remove(); body.appendChild(newScriptTag);
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!