# Javascript inserted into Footer from Discourse UI not working

**URL:** https://meta.discourse.org/t/javascript-inserted-into-footer-from-discourse-ui-not-working/40531
**Category:** Support
**Created:** [March 3, 2016, 7:25pm UTC](https://meta.discourse.org/t/javascript-inserted-into-footer-from-discourse-ui-not-working/40531 "2016-03-03T19:25:25Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![stevenpslade](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stevenpslade/32/53550_2.png) [@stevenpslade](https://meta.discourse.org/u/stevenpslade)
#### Post date: [March 3, 2016, 7:25pm UTC](https://meta.discourse.org/t/javascript-inserted-into-footer-from-discourse-ui-not-working/40531/1 "2016-03-03T19:25:25Z")

</div>

Continuing the discussion from [How do I insert javascript into the footer?](https://meta.discourse.org/t/how-do-i-insert-javascript-into-the-footer/28056):

In Footer of the Discourse UI I am trying to get javascript to run but it does not and there are no errors. It’s as if it just isn’t present.

```
<script>
console.log("anything");
</script>

```

This is in Footer, nothing console.logs. It is Enabled, too.

---

<div class="post-metadata">

### Author: ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)
#### Post date: [March 3, 2016, 8:20pm UTC](https://meta.discourse.org/t/javascript-inserted-into-footer-from-discourse-ui-not-working/40531/2 "2016-03-03T20:20:41Z")

</div>

Looks like a bug…

I just tried it with both JavaScript and normal content and neither appeared:

 ![](https://global.discourse-cdn.com/meta/original/3X/3/f/3fd2eb8a86c80e8a43c7971ab89ce9388a7352b3.png)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [March 4, 2016, 2:52am UTC](https://meta.discourse.org/t/javascript-inserted-into-footer-from-discourse-ui-not-working/40531/3 "2016-03-04T02:52:17Z")

</div>

Hmm can we repro this @techapj?

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [March 4, 2016, 5:26am UTC](https://meta.discourse.org/t/javascript-inserted-into-footer-from-discourse-ui-not-working/40531/4 "2016-03-04T05:26:13Z")

</div>

Looking at the [code](https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/templates/application.hbs#L15-L17) by which footer is inserted, I believe it’s not possible to insert JavaScript via `Footer` and `Top`.

The only sections which supports injecting JavaScript are `Header`, `</head>` and `</body>`.

* * *

> [@DeanMarkTaylor](#):
>
> normal content

I am not able to repro this, normal content appears fine in Footer. Also here is one of our hosted instance which has custom Footer:

[http://forums.mtbakervapor.com/t/welcome-to-mt-baker-vapors-discourse/6](http://forums.mtbakervapor.com/t/welcome-to-mt-baker-vapors-discourse/6)

Looks just fine.

---

<div class="post-metadata">

### Author: ![stevenpslade](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stevenpslade/32/53550_2.png) [@stevenpslade](https://meta.discourse.org/u/stevenpslade)
#### Post date: [March 10, 2016, 11:58pm UTC](https://meta.discourse.org/t/javascript-inserted-into-footer-from-discourse-ui-not-working/40531/5 "2016-03-10T23:58:43Z")

</div>

How is one to include a JS script that is run after the page has loaded (and keep in mind it can’t be done with a document ready. It needs to be in the footer.

---

<div class="post-metadata">

### Author: ![kourou](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kourou/32/62572_2.png) [@kourou](https://meta.discourse.org/u/kourou)
#### Post date: [September 20, 2016, 8:25pm UTC](https://meta.discourse.org/t/javascript-inserted-into-footer-from-discourse-ui-not-working/40531/6 "2016-09-20T20:25:32Z")

</div>

Hello.

Is there any update on this issue?

I am also trying to include javascript code in top/footer but it is not working.  
What I want to do, is insert (for example) google adsense or AdTech tags in Top/Footer, but it seems that the script is not executed.  
In Header (Customize → CSS/HTML → Header), however, the script is working as expected.

Can you please fix it?

Thanks,  
Ilias

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [September 21, 2016, 4:36am UTC](https://meta.discourse.org/t/javascript-inserted-into-footer-from-discourse-ui-not-working/40531/7 "2016-09-21T04:36:20Z")

</div>

> [@kourou](#):
>
> Is there any update on this issue?

Nothing is broken here, have a look at examples of supported ways of adding scripts, for example:

> [@Matomo Analytics](https://meta.discourse.org/t/how-to-enable-piwik-analytics-on-discourse/33090):
>
> discourse2Summary Matomo Analytics is a script to enable Matomo analytics on Discourse.hammer_and_wrenchRepository Link [https://github.com/discourse/discourse-matomo-analytics](https://github.com/discourse/discourse-matomo-analytics)open_bookNew to Discourse Themes? [Beginner’s guide to using Discourse Themes](https://meta.discourse.org/t/beginners-guide-to-using-discourse-themes/91966) Install this theme component Features [Matomo](https://matomo.org/) is an open source analytics platform. Users can choose between self-hosting or paying for professional hosting in the cloud. mega Matomo was formerly named Piwik. S…

---

<div class="post-metadata">

### Author: ![kourou](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kourou/32/62572_2.png) [@kourou](https://meta.discourse.org/u/kourou)
#### Post date: [September 21, 2016, 5:24am UTC](https://meta.discourse.org/t/javascript-inserted-into-footer-from-discourse-ui-not-working/40531/8 "2016-09-21T05:24:58Z")

</div>

If I add the same script to **Header** (Admin / Customize / CSS/HTML / Header) and **Footer** (Admin / Customize / CSS/HTML / Footer), it is working only in Header, that’s what I’m saying.

You can try this out yourself. I just did the test with default Google Adsense tags, but you can test it with any simple script, for example:

```
<script>
    alert("script executed");
</script>

```

In “Footer” this will not popup the dialog, whereas in “Header” this will work.

Thank you,  
Ilias

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [September 21, 2016, 5:41am UTC](https://meta.discourse.org/t/javascript-inserted-into-footer-from-discourse-ui-not-working/40531/9 "2016-09-21T05:41:19Z")

</div>

> [@kourou](#):
>
> In “Footer” this will not popup the dialog, whereas in “Header” this will work.

Footer is not designed to allow for script tags, it is just for visual changes.

The lifecycle of our application is very different to what a traditional webpage is. There are hooks in Ember you need to use if you need code to run

- On initialization
- On page transition
- When a route is entered
- When a component is rendered

and so on.

The to make XYZ work put the following “snippet” in your HTML footer concept make no sense for a single page application.

---

<div class="post-metadata">

### Author: ![kourou](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kourou/32/62572_2.png) [@kourou](https://meta.discourse.org/u/kourou)
#### Post date: [September 21, 2016, 6:00am UTC](https://meta.discourse.org/t/javascript-inserted-into-footer-from-discourse-ui-not-working/40531/10 "2016-09-21T06:00:48Z")

</div>

> [@sam](#):
>
> Footer is not designed to allow for script tags, it is just for visual changes.
> 
> The lifecycle of our application is very different to what a traditional webpage is. There are hooks in Ember you need to use if you need code to run

Got it, thanks.  
I will look for any howto on implementing these hooks. If there is any tutorial about it here in meta, please advise.

---

<div class="post-metadata">

### Author: ![frostydog](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/frostydog/32/68228_2.png) [@frostydog](https://meta.discourse.org/u/frostydog)
#### Post date: [March 6, 2017, 6:48pm UTC](https://meta.discourse.org/t/javascript-inserted-into-footer-from-discourse-ui-not-working/40531/11 "2017-03-06T18:48:17Z")

</div>

This is happening to me today. When I insert a Javascript on the `</body>` section, I just cannot save.

v1.8.0.beta5 +211

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [May 9, 2019, 4:29pm UTC](https://meta.discourse.org/t/javascript-inserted-into-footer-from-discourse-ui-not-working/40531/12 "2019-05-09T16:29:28Z")

</div>



---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [May 10, 2019, 5:32am UTC](https://meta.discourse.org/t/javascript-inserted-into-footer-from-discourse-ui-not-working/40531/13 "2019-05-10T05:32:53Z")

</div>


