Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

510
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!