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

130
Vistas
Execute injected script element after it has been loaded dynamically

I make an ajax request that injects a script node in my head or body element like this:

window.addEventListener("DOMContentLoaded", () => {

    this._client.get('/getFragment', (responseText) => {
        const obj = JSON.parse(responseText);
        const scriptTag = document.createElement('template');
        scriptTag.innerHTML = obj.fragment;

        document.body.appendChild(scriptTag.content);
    });
});

The issue now is that the script is injected into the DOM, but as this JS script calls another external URL I can see in the network monitor that the URL of the script is not called/executed. How can make sure that the script tag is executed after I injected it into the DOM?

The fragment that I would like to inject is this one:

<script id="mcjs">!function(c,h,i,m,p){m=c.createElement(h),p=c.getElementsByTagName(h)[0],m.async=1,m.src=i,p.parentNode.insertBefore(m,p)}(document,"script","https://chimpstatic.com/mcjs-connected/js/users/1f.js");</script>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I'm not quite sure I understand what you are asking, but I believe the the problem is that you are creating a template element, and browsers usually doesn't execute the content of those. Try using document.createElement('div') instead.

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