How to add Jquery to MasterPage 2013

对着背影说爱祢 提交于 2019-12-12 01:58:52

问题


I'm trying to add jQuery to sharepoint 2013 master page. What I did:

1)

  • Copy jquery - "jquery-1.11.1.min.js" to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS.
  • Copy seattle.html and add <!--SPM:<SharePoint:ScriptLink language="javascript" name="/_layouts/jquery-1.11.1.min.js" runat="server" Localizable="false" />-->
  • Upload seattle.html as ASP NET MASTERPAGE
  • Publish it ---> Nothing happend. To seattle.master wasn't appear Sharepoint:Scriptlink

2)

  • Copy jquery - "jquery-1.11.1.min.js" to SiteAssets. My application is on root site collection so for instance access to jquery is

http://localhost/SiteAssets/jquery-1.11.1.min.js

  • Copy seattle.html
    • Add !--SPM:<SharePoint:ScriptLink language="javascript" name="'~sitecollection/SiteAssets/jquery-1.11.1.min.js" runat="server" Localizable="false" />-->
    • Still no effect

What is the correct way from begining to the add of adding Jquery to Sharepoint 2013?


回答1:


Probably you forgot to apply custom master page, go to Master Page settings page and set Site Master Page and System Master Page to your custom master page.

Note: there is a typo in the second option: name attribute contains ' symbol

How to reference JavaScript file in SharePoint 2013 master page

Assume the following scenario:

  • a custom master page helsinki.master with associated HTML file are used
  • jQuery library jquery.min.js is located in SharePoint Site Assets library

Then, in order to reference jQuery library in custom master page the following steps are used:

  • Open an associated HTML file helsinki.html
  • Insert the line <!--SPM:<SharePoint:ScriptLink language="javascript" name="~sitecollection/SiteAssets/jquery.min.js" runat="server" Localizable="false"/>-->
  • Publish helsinki.html
  • Go to Master Page settings page and set Site Master Page and System Master Page to helsinki.master

About System Master Page

System Master Page is used by administrative pages, lists, and document library views on this site

This approach has been tested in SharePoint 2013 and works for me.




回答2:


i would suggest to add jQuery with a custom DelegateControl. With this approach there is no need to modify the MasterPage. Every Masterpage contains a placeholder where you are able to hook in custom scripts, like jQuery.

Here is a detailed description how to develop the solution: http://blogs.msdn.com/b/kaevans/archive/2011/04/06/adding-jquery-to-every-page-in-sharepoint-with-delegate-controls.aspx

The cool thing with the delegateControl is, that you can use any scopes for this Solution. So you can apply jQuery to the whole Farm, Webapplication, Sitecollection or Web.

Regards



来源:https://stackoverflow.com/questions/25305168/how-to-add-jquery-to-masterpage-2013

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!