Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

148
Vistas
add external html with javascript code without using iframe

I'm trying to load some html and javascript from one website without using iframe. I can render the html, css and it seems that the javascript files are being loaded, but I can't call functions from the loaded content.

I'm trying to load using 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
        });
}();

Is it possible, or it's blocked by browsers for security reasons?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

you have to explicitly add a script element.
so what works for sure is:

 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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda