Help with js to insert into a topic

Hello!

I need to insert <script src="https://xxxxx.js" async></script> into a topic, just ONE topic.

I knew this:

But it is possible to use javascript to check the url and if it match, insert the js? :thinking:

2 Likes

After typing this, an idea hit my head:

    <script type="text/javascript">
    if(window.location.href === "https://my-forum.com/t/xxxxx/1234567") {
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'https://xxxxxxx.js';
    head.appendChild(script);
    }
    </script> 

It’s working fine ! :+1:

5 Likes