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

511
Vistas
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 Respuestas
Responde la pregunta

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 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