0

I am in the process of migrating from SP2010 to SP2013. In SP2010 the Scriptlink feature was used to upload all of the jQuery libraries from the master page. Currently I want to test some web parts in SP2013 since the master page is not yet ready. The problem is that the web parts do not have the jQuery files they need to run. Is there a way I can put the jQuery.min.js file/libraries into the web parts so they do not require master page to run? Where would I put it?

Thanks for the help in advance!

2 Answers 2

2

The master page method is still the best when you have multiple different areas of the site calling jQuery. For what you describe, though, you can just drop a Script Editor web part onto the page and call your jQuery there using standard script tags.

The Script Editor web part is new to 2013 and is basically a Content Editor Web Part (CEWP) that's already hidden and customized for adding code snippets (as opposed to HTML content like the CEWP). It provides a handy way to add CSS or JavaScript to the page. It's located in the "Media and Content" category along with the CEWP.

2

If you wanted to avoid having to make a master page change at all you could create a new feature instead that inserts the code into the AdditionalPageHead Delegate Control. See http://blogs.msdn.com/b/kaevans/archive/2011/04/06/adding-jquery-to-every-page-in-sharepoint-with-delegate-controls.aspx.

As requested, here's more information: First, another link from MSDN that specifically covers adding JavaScript to the AdditionalPageHead control - http://msdn.microsoft.com/en-us/library/office/ms470880(v=office.14).aspx.

The basic idea is that SharePoint has several delegate control areas designed for you to change or add to them. The AdditionalPageHead area is specifically designed for injecting JavaScript, such as a link to the JQuery source file. This does require creating a project in VisualStudio to build a new feature which then has to be deployed and activated. Relevant items in the solution are:

  1. A User Control where the reference to the file is added.

    <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
    
  2. An Elements file to reference the user control.

    Note - the TemplateName="GLOBAL" parameter makes it on be default for all new sites created.

  3. The jQuery (or whatever .js file you are adding) file if not already at a common location.

2
  • While this is certainly an appropriate solution to this problem, the answer would be better if you included relevant details from the link in your post. This will help future proof the answer in case the blog is ever moved or removed. May 12, 2014 at 21:48
  • Yes, could you please elaborate on this solution? I'm not quite sure whats actually happening in this link. May 13, 2014 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.