How to add JS in After Header?

This is simply not possible. Note, the developers guide mentions you have only three options for script tags to fire:

Is there a particular reason you need the code in the after_header? There may be other approaches you can take to achieve what you need.

When you tried separating the script in the head and the button in the after_header, are you sure the script is not firing at all, or is it that you are unable to select the button? It may be due to the way the Ember runloop is.

Perhaps you can try wrapping your script in an

<script type="text/discourse-plugin" version="0.8" >
api.onPageChange(() => {
   var btn = document.querySelector('#Send');

   btn.addEventListener('click', function(e) {
     e.preventDefault();
  
    this.disabled = true;
  
     setTimeout(function(){ btn.disabled=false; }, 10000);
   });

});
</script>
3 Likes