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

514
Visualizações
How can I exclude this JS code from running on certain URL strings?

I have some JS code (Swarmify) running on every page of my website (mydomain.com) that changes the skin of YouTube videos (to Swarmify).

I can modify this code in the parent site dashboard.

I want to exclude it from running on certain pages (mydomain.com/blog*), by editing the parent code; i.e. I want all my blog videos to be simply embedded YouTube videos without needing to edit each individual blog post.

I don't know JS at all.

Is there a way/command I can insert that will add the URL string exception? (and using a wildcard; i.e. all pages that begin mydomain.com/blog*)

Here is the code (the cdnkey has been amended : )).

<!-- start Swarmify JS code-->
<script data-cfasync="false">
    var swarmoptions = {
        swarmcdnkey: "myrandomstring",
        iframeReplacement: "iframe",
        autoreplace: {
            youtube: true
        },
        theme: {
            primaryColor: "#eb6a56"
        }
    };
</script>
<script async data-cfasync="false" src="https://assets.swarmcdn.com/cross/swarmdetect.js"></script>
<!-- end Swarmify JS code-->

I contacted the developer but they were unable to help.

As per this post answer, I added the suggested JS script (see below) which stopped Swarmify running (good!), but stopped it on all pages of my website, not just blog pages (bad!).

Perhaps I didn't add that code in the right way?

<script data-cfasync="false">
if (window.location.href.indexOf('/blog*') != -1) {
   //don't run on blog pages
   return;
}
    var swarmoptions = {
        swarmcdnkey: "myrandomstring",
        iframeReplacement: "iframe",
        autoreplace: {
            youtube: true
        },
        theme: {
            primaryColor: "#eb6a56"
        }
    };
</script>
<script async data-cfasync="false" src="https://assets.swarmcdn.com/cross/swarmdetect.js"></script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can try the below code. I hope it will solve your problem.

<script data-cfasync="false">
        var swarmoptions = {};
        window.addEventListener('DOMContentLoaded', (event) => {
        if (/\/blog[.]*/ig.test(window.location.toString())) {

            return;
        }
        swarmoptions = {
            swarmcdnkey: "myrandomstring",
            iframeReplacement: "iframe",
            autoreplace: {
                youtube: true
            },
            theme: {
                primaryColor: "#eb6a56"
            }
        };
    });
</script>
<script async data-cfasync="false" src="https://assets.swarmcdn.com/cross/swarmdetect.js"></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