SharePoint Custom JS file Best Practice

后端 未结 4 559
故里飘歌
故里飘歌 2021-02-04 16:37

I made a custom master page. I also made a custom CSS file, which I uploaded to \"Style Library\". I link to this CSS file by:



        
相关标签:
4条回答
  • 2021-02-04 16:45

    Check out the SharePoint:ScriptLink class, which is similar to the SharePoint:CssRegistration.

    The documentation is pretty sparse, but try this http://www.go4sharepoint.com/Forum/sharepointscriptlink-6462.aspx

    0 讨论(0)
  • 2021-02-04 16:47

    You can upload that js file in site collection document library, if you want to get this to all site collections then please create a folder in side layouts and paste it there. And refer this is in your custome master page.

    0 讨论(0)
  • 2021-02-04 16:54

    You can store JS files in the _layouts folder, but storing them in the Style Library gives you workflow/change history for free.

    If you keep your JS files in the Style Library you can reference them in your MasterPage using the ~sitecollection token by using the <SharePoint:Scriptlink> tag, like so:

    <SharePoint:Scriptlink runat="server" Name="~sitecollection/Style Library/[YOUR SITE]/js/functions.js" Language="javascript" />
    
    0 讨论(0)
  • 2021-02-04 17:03

    Use Style Library and use CssRegistration and ScriptLink if they work. But sometimes SharePoint puts the links in an order you don't want. In that case, you can use the following to directly insert the references:

    <link rel="stylesheet" type="text/css" href="<% $SPUrl:~SiteCollection/Style Library/coe/mainCOE.css%>" runat="server"/>
    <script type="text/javascript" language="javascript" src='<asp:Literal runat="server" Text="<%$SPUrl:~SiteCollection/Style Library/coe/mainCOE.js%>" />'></script>
    
    0 讨论(0)
提交回复
热议问题