People often ask about how to add custom JavaScript to their site or custom features. For some scenarios, you can add the needed scripts directly in the layout.master file of your skin, but for custom features you may not want that script on every page but only on the page where your feature exists. 

As of mojoPortal version we now have a Custom JavaScript feature that can be added to CMS pages like any other feature and you can specify the url to the script or 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.

When developing a custom feature, you can register your script(s) from code like this:

     "uniqueidforyourscript", "\n<script type=\"text/javascript\" 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');"
"idforyourscript", "\n<script type=\"text/javascript\" >"
+ initScript + "</script>");
Last Modified: Dec 03, 2020