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

120
Vistas
How to Include Javascript inside document.write properly or is there a workaround?

I am forced to put code in a place where- when inserted, it applies to thousands of web pages at the same time.

I would like to only have a script work when a URL contains: "/pN2toKYZ/checkout" :

So i used window.location.href.indexOf and that seems to work well, but im having trouble after that.

Here is what I am trying, I have also tried escaping the starting'<' but it did not work:

<script>
if (window.location.href.indexOf('/pN2toKYZ/checkout') != -1) {
   document.write("<script>
  gtag('event', 'conversion', {'send_to': 'AW-834461893/ixLXCK-Wm6kDEMXB840D'});
 </script>
")
}
</script>

Note: the script i'm trying to place is a Google Adwords conversion tag. Google Adwords general script is rightfully in place before this code.

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

0

You're already running inside a script element - instead of trying to write a new script to the page, put the code you want to run directly:

<script>
if (window.location.href.indexOf('/pN2toKYZ/checkout') != -1) {
  gtag('event', 'conversion', {'send_to': 'AW-834461893/ixLXCK-Wm6kDEMXB840D'});
}
</script>
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