Custom action fetches an external script and includes it in the page. So at run time the script will self execute as an anonymous function.

Following are few scenarios you may need this functionality in your SharePoint Projects:

  1. Override the new sub site link under Site Contents  with your site provisioning app URL

  2. Redirect the user to specific page

  3. Inject third-party JavaScript libraries such as Jquery, Knockout, AngularJs, etc.,

  4. Add dynamic html (global navigation or company copy rights information on the bottom of your page) content on your sharepoint page at run time without even modifying the actual master page.

In the below example, I have explained how to inject Jquery file to one of my web. The source files can be placed in CDN/File Share/Common Location such as App Catalog.

Feel free to change the logic as per your requirement.

Note: The logic remains same for JSOM code also.

inject_action