Add HTML Before the Closing Body Tag

Jake Peters Updated by Jake Peters

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 Javascript 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 > Javascript šŸ™ƒ

<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?

Adding Lightboxes to Images

Customizing Feedback Icons

Get in touch