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

259
Visualizações
How to catch error in googletag.cmd.push(function() { googletag.display('div-id'); });?

I am trying to catch the error on
 googletag.cmd.push(function() { googletag.display('div-id'); });

While I know the root of the problem is because the slot is not defined in the head, how can I catch the error? I'm facing a problem where the definedSlot is messy and all over the place so I think catching the error in the googletag.cmd.push would be an easier solution.
Thank you.
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

you can check wether the targeted ID in the googletag defined slots exists in the DOM before displaying it :

    //get all the defined slots
    var definedSlots = googletag.pubads().getSlots();
    //loop through the definedSlots
    for (var x = 0; x < definedSlots.length; x++) {
       //retrieve the targeted ID
       var slotId = definedSlots[x].getSlotId().getDomId();
       //if it exists
       if (document.querySelector('#'+ slotId)) {
          //then dislay it
          googletag.cmd.push(function() { googletag.display(slotId); });
       }
     }
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