2

after going through the this link How to implement JavaScript in master page of SharePoint 2013 and JavaScript files are not loading in masterpage for adding a reference for js file , thats residing in the 15 layouts folder, am facing issues.

am not able to get the script executed from master page.

I tried to add the file in the mycustommaster.htm file as well. if i tried to add the line of adding js file reference in mycustommaster.master, its also not reflecting. How to add a reference js file within the custom master using SP 2013 ?

below is my html page's code, where in name="/_layouts/15/1033/NPDSCRIPTS/NPDECBMenu.js is my custom code is kept.

        <!--SPM:<SharePoint:ScriptLink language="javascript" 
    name="suitelinks.js" OnDemand="true" runat="server" 
    Localizable="false"/>-->
    <!--SPM:<SharePoint:Scriptlink language="javscript" 
      name="/_layouts/15/1033/NPDSCRIPTS/NPDECBMenu.js" OnDemand="true" 
   runat="server" Localizable="false"/>-->
    <!--SPM:<SharePoint:CustomJSUrl runat="server"/>-->
    <!--SPM:<SharePoint:SoapDiscoveryLink runat="server"/>-->
    <!--SPM:<SharePoint:AjaxDelta id="DeltaPlaceHolderAdditionalPageHead" 
 Container="false" runat="server">-->
  • can you paste code that you have used to link javascript file? – Alok Kumar Gupta Mar 28 '17 at 9:11
2
  • Upload your js file to Style Library in SharePoint site collection rather than 15\layouts

  • Open SharePoint Designer > Go to Master Page > Right click on your custom master page HTML file and Check it out.

  • Right click -> Edit in advanced mode.
  • In < head > section add your reference of your js file like <script type="text/javascript" src="../../Style Library/JS/jquery7.min.js">

Note: To get the correct URL > write Src=" > then the Pick URL button should be shown, navigate to your js file in Style Library.

  • Save -> Right click Check-in -> Publish As Major version ->

Enter image description here

  • This is will open your master page gallery -> right click and select publish.

Enter image description here

  • 1
    M.Qassas, the reason I went with the 15 template layouts folder for storing the js, css, image files because of higher performance. I have read somewhere, its better to store these files in the 15 hive filesystem rather than storing/uploading in style library / site assets lib. Is there any other reason you are suggesting to upload the files into style lib? – userAZLogicApps Mar 28 '17 at 11:46
  • 1
    sorry for the delayed reply, this is a confusion topic since 2007 .Meanwhile, both location should be working and every location has its advantage and disadvantage that you can check it here in details sharepoint.stackexchange.com/questions/2219/… if you ask for my opinion it's visibility scope rather than performance, if you plan on implementing the css/js files into more than one web app/site collection. for me I will put it in Style Library for the same mentioned reason in the above link :) – Mohamed El-Qassas MVP Mar 28 '17 at 15:01
2

To apply custom resources to master page, we modify associated html file which is a recommended practice by Microsoft. And we will only modify html tags. Below is our way to include css and javascript files. enter image description here

In your case you can refer as follows

<script type="text/javascript" src="/_layouts/15/1033/NPDSCRIPTS/NPDECBMenu.js">//<![CDATA[

    //]]>
    </script>

The place to add this line of code can be refered from the image

1

Can you try changing code to:

<!--SPM:<SharePoint:Scriptlink language="javscript" 
      name="/_layouts/15/1033/NPDSCRIPTS/NPDECBMenu.js"
   runat="server" Localizable="false"/>-->

Please also check if same master page is set for both "Site Master Page" as well as "System Master Page". In publishing sites, "System Master Page" is the primary master page.

  • I have a doubt here, why, if I make changes in the custommaster.master page doesn't reflect? I know as per the 2013 architecture, I have custommaster.html file and we need to make changes in the html file first and then it will be auto.reflected. but here in my case, if I make changes to html file, its somehow not reflecting. am confused about the tags , elements in .html file. How to manage these 2 files? <li> should I perform the changes/additions/deletions from html file first and then I need to publish from the master page gallery? – userAZLogicApps Mar 28 '17 at 11:37
  • 1
    you are right. when one makes changes to html page linked with master page and saves it, it gets automatically converted to master page. one should not make changes to master page directly. Making changes to master pages can be cause of issues. Make changes to html files only and then publish html page. That will automatically publish master page as well. – Alok Kumar Gupta Mar 28 '17 at 11:44
0

I tried all the steps above with no luck. After the following additional steps I was ultimately successful:

  • I created a new copy of the seattle.html
  • I placed my scriptlink under the reference of the corev15.css in my custom masterpage html

    <!--SPM:<SharePoint:CssRegistration Name="Themable/corev15.css" runat="server"/>-->
    <!-- Custom Scripts -->
    <script type="text/javascript" src="../../Style Library/Congstar/Scripts/congstar-global.js">//<![CDATA[//]]>
    </script>
    <!-- End Custom Scripts -->
    

I don't know why but check-in and publishing the .html was no solution... and I did it several times.
I asserted that my changes in .html did not affect the .master. Maybe that's the problem. So, creating a new masterpage .html did it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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