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

151
Views
agregue html externo con código javascript sin usar iframe

Estoy tratando de cargar algo de html y javascript desde un sitio web sin usar iframe. Puedo renderizar el html, css y parece que los archivos javascript se están cargando, pero no puedo llamar a funciones desde el contenido cargado.

Estoy tratando de cargar usando fetch:

 window.onload = function () { fetch(myURL) .then(function (response) { return response.text(); }) .then(function (body) { var dv = document.createElement('div'); dv.innerHTML = body; document.body.appendChild(dv); //trying to call function here after appending the html content to my page }); }();

¿Es posible o está bloqueado por los navegadores por razones de seguridad?

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

0

tiene que agregar explícitamente un elemento de secuencia de comandos.
entonces lo que funciona con seguridad es:

 let text = "<h1>Test</h1><script>const callMe = () => { alert('called'); }" + "&lt;/script>"; const scriptStart = text.indexOf('<script>'); const scriptEnd = text.indexOf('&lt;/script>'); const script = text.substring(scriptStart + "<script>".length, scriptEnd); text = text.substring(0, scriptStart) + text.substring(scriptEnd + "&lt;/script>".length); element.innerHTML = text; const scriptElement = document.createElement("script"); scriptElement.innerHTML = script; document.head.appendChild(scriptElement); callMe();
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!