Add HTML Before the Closing Body Tag

Matt Bradford-Aunger Updated by Matt Bradford-Aunger

Customizing your docs with JavaScript snippets and CSS is an awesome way to make them stand out.

Most of the time you'll find dropping your custom code into Settings > Code > CSS or Scripts works super well by adding code into the <head> portion of your knowledge base. But there might be the odd occasion where you'll wanna add a snippet somewhere else. Sometimes scripts need to be added before the closing </body> tag.

For this you'll wanna use the example below replacing Your Code with your custom code and saving the entire snippet into Settings > Code > Scripts 🙃

<script>
 var someHTML = 'Your Code'; // string of HTML here
 ready(function() {
   document.body.insertAdjacentHTML('afterend', someHTML);
 })

 function ready(fn) {
   if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading"){
     fn();
   } else {
     document.addEventListener('DOMContentLoaded', fn);
   }
 }
</script>

What did you think of this doc?

How to Change the Logo Link

Overriding the Font on Your Knowledge Base

Get in touch