Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

121
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda