# Help with js to insert into a topic

**URL:** https://meta.discourse.org/t/help-with-js-to-insert-into-a-topic/83772
**Category:** Support
**Created:** [March 24, 2018, 9:35pm UTC](https://meta.discourse.org/t/help-with-js-to-insert-into-a-topic/83772 "2018-03-24T21:35:27Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![SidV](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sidv/32/119460_2.png) [@SidV](https://meta.discourse.org/u/SidV)
#### Post date: [March 24, 2018, 9:35pm UTC](https://meta.discourse.org/t/help-with-js-to-insert-into-a-topic/83772/1 "2018-03-24T21:35:27Z")

</div>

Hello!

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

I knew this:

> [@How do i insert Javascript into a Topic?](https://meta.discourse.org/t/how-do-i-insert-javascript-into-a-topic/44429/2):
>
> You can only insert JS via Admin, Customize in the header or footer.

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

---

<div class="post-metadata">

### Author: ![SidV](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sidv/32/119460_2.png) [@SidV](https://meta.discourse.org/u/SidV)
#### Post date: [March 24, 2018, 9:56pm UTC](https://meta.discourse.org/t/help-with-js-to-insert-into-a-topic/83772/2 "2018-03-24T21:56:57Z")

</div>

After typing this, an idea hit my head:

```javascript
    <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 ! 👍

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [June 8, 2024, 12:37pm UTC](https://meta.discourse.org/t/help-with-js-to-insert-into-a-topic/83772/3 "2024-06-08T12:37:43Z")

</div>

This topic was automatically closed after 2267 days. New replies are no longer allowed.
