none
How to inject Jquery Code in SharePoint to be executed on every Page of a sharepoint site without modifying the master page?

    Question

  • Hi

    What I should do to inject Jquery Code into SharePoint that will be executed on every Page of a SharePoint site without editing the masterpage.

    Is there a specific way to use Jquery to avoid any conflict with the existing javascript code in  SharePoint?

    Thanks,

    Regards,

    Akli


    arioule


    • Edited by Kabylie Saturday, November 11, 2017 1:08 AM
    Saturday, November 11, 2017 12:46 AM

Answers

All replies

  • Hi,

    You can use Delegate Controls to add jQuery to each page of SharePoint without modifying it.There are multiple Delegate Controls available OOB in SharePoint Master page like the one below. You can over ride them using a webpart to inject jQuery into master page without modifying it. 

    <SharePoint:DelegateControl runat="server" 
              ControlId="AdditionalPageHead" 
              AllowMultipleControls="true"/>

    Delegate controls are particularly useful in SharePoint when you want to add functionality to all pages within your site without changing the master page. For example, if you want to add an external JavaScript library (such as JQuery) to every page, you can do this easily by registering a delegate control. An example of this approach can be seen here

    You can also refer these examples :

    Example 1

    Example 2

    Regards,

    Priyan


    Please Up Vote and Mark this as Answer if it helps.


    Saturday, November 11, 2017 6:07 AM
  • Hi Akli,

    We can inject JavaScript to any Site or Site Collection via a User Custom Action's ScriptLink property.

    The following articles for your reference:

    The easiest way to add Script and Brand your SharePoint and SharePoint Online

    http://johnliu.net/blog/2015/12/the-safest-future-proof-way-to-brand-your-sharepoint-and-sharepoint-online

    UserCustomActionsConfigPage

    https://github.com/johnnliu/UserCustomActionsConfigPage

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com


    Monday, November 13, 2017 7:22 AM
    Moderator