问题
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
- Add
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 SharePointSite 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
andSystem Master Page
tohelsinki.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