Users are experiencing issues inserting JavaScript into the Footer section of their Discourse UI, with no errors or console logs appearing. techAPJ explained that only the Header, </head>, and </body> sections support injecting JavaScript, while the Footer section is only for visual changes.
Sam elaborated that the lifecycle of a single-page application like Discourse is different from a traditional webpage, and hooks in Ember are needed to run code at specific times. Users are advised to use these hooks instead of inserting scripts in the Footer.
Multiple users have reported this issue, including stevenpslade, kourou, and frostydog, who also encountered issues with saving JavaScript in the </body> section.
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.
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.
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.