I want to include javascript below the footer and before the closing body tag, but only on a few pages. How can I do this?
Can use something like:
---
videos: true
---
in the frontmatter of the pages that need the script and then some code placed in the footer.html, like:
`</footer>`
{{- Param.videos true -}}
`<script>document.addEventListener("DOMContentLoaded", function() {var div, n, v = document.getElementsByClassName("youtube"); for (n = 0; n < v.length; n++) { div = document.createElement("div"); div.setAttribute("data-id", v[n].dataset.id); div.innerHTML = labnolThumb(v[n].dataset.id); div.onclick = labnolIframe; v[n].appendChild(div);}});function labnolThumb(id) {var thumb = '<img src="https://i.ytimg.com/vi/ID/hqdefault.jpg">', play = '<div class="play"></div>'; return thumb.replace("ID", id) + play;} function labnolIframe() {var iframe = document.createElement("iframe"); var embed = "https://www.youtube-nocookie.com/embed/ID?autoplay=1&rel=0"; iframe.setAttribute("src", embed.replace("ID", this.dataset.id)); iframe.setAttribute("frameborder", "0"); iframe.setAttribute("allowfullscreen", "1"); this.parentNode.replaceChild(iframe, this);}</script>`
{{ end }}
</body>
</html>
(btw…I know that the code doesn’t work, I just wanted to give an example of what I mean)
How can I do this?