Continuing the discussion from How do I insert javascript into the footer? :
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.
2 Likes
Looks like a bug…
I just tried it with both JavaScript and normal content and neither appeared:
1 Like
Hmm can we repro this @techapj ?
techAPJ
(Arpit Jalan)
March 4, 2016, 5:26am
4
Looking at the code 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
Looks just fine.
3 Likes
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.
kourou
(Ilias)
September 20, 2016, 8:25pm
6
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
sam
(Sam Saffron)
September 21, 2016, 4:36am
7
Nothing is broken here, have a look at examples of supported ways of adding scripts, for example:
Matomo is an open source analytics platform. Users can choose between self-hosting or paying for professional hosting in the cloud.
Matomo was formerly named Piwik. See Piwik is now Matomo - Announcement - Analytics Platform - Matomo for details about the name change.
You have to whitelist your Matomo-URL inside the Content-Security-Policy-Header. Search for the admin setting content_security_policy_script_src and add your domain (with https://) there
To enable Matomo ana…
1 Like
kourou
(Ilias)
September 21, 2016, 5:24am
8
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
sam
(Sam Saffron)
September 21, 2016, 5:41am
9
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.
2 Likes
kourou
(Ilias)
September 21, 2016, 6:00am
10
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.
frostydog
(Ed Arcos)
March 6, 2017, 6:48pm
11
This is happening to me today. When I insert a Javascript on the </body>
section, I just cannot save.
v1.8.0.beta5 +211