People often ask about how to add custom JavaScript to their site or custom features. If you're placing script on your site from a 3rd party, be sure you trust the source and you know what the script is supposed to be doing.
Adding JavaScript to the Entire Site
This is useful when you need to add script to support an external service, like a chatbot, analytics, or an accessibility widget.
Simply go to Administration > Site Settings and select the "Custom Content" tab.
There are two areas you can add your script, the page <head> or the bottom, just above the closing </body> element. The instructions for your particular script should tell you which is the best place to put it.
Additionally, you can add script to every CMS page or to the admin pages.
Adding JavaScript to a CMS page
Using the Custom JavaScript feature you can add JavaScript to any CMS page, just like any other feature. You can specify the URL to the script or paste the actual script in the settings, with options for placing the script in the head, at the bottom, or in the content position of the feature instance. You will find it in the feature list dropdown in page edit view.
Adding JavaScript to your custom feature
When developing a custom feature, you can register your script(s) from code like this:
Page.ClientScript.RegisterClientScriptBlock(typeof(Page),
"uniqueidforyourscript", "\n<script data-loader=\"MyCustomModule\" src=\""
+ Page.ResolveUrl("~/ClientScript/pathtoyourscript.js") + "\" ></script>");
For initialization scripts that you want to load at the bottom of the page you can do it like this:
string initScript = "alert('hello world');"
Page.ClientScript.RegisterStartupScript(typeof(Page),
"idforyourscript", "\n<script data-loader=\"MyCustomModule\" >"
+ initScript + "</script>");
Last Modified by Joe Davis on Mar 31, 2025