-1

I have applied master page using JavaScript in my SharePoint Hosted App. This script reference is added on default.aspx. Now I want to add script reference on master page which I have applied so that it will work on all hierarchy. Suppose I have two links

https://domain.com/site/appname/default.aspx

https://domain.com/site/appname/Lists/listname.aspx

I have tried with below reference

<script src="../Scripts/FieldToHide.js" type="text/javascript"></script>

but t works only for default.aspx page but not under Lists folder

So Is it possible to provide such reference. If yes how? Thanks in advance

  • 2
    Use the full absolute path to the JS file maybe? – Eric Alexander Mar 30 '16 at 13:08
  • are you inserting on custom master page or seattle? – Rajesh Joshi Mar 30 '16 at 13:11
  • custom master page – Mrunal Shidurkar Mar 30 '16 at 13:12
  • 1
    @MrunalShidurkar Specify a system master page for this site and all sites that inherit from it : set your custom master page here also. Site Setting -> Master Page – Rajesh Joshi Mar 30 '16 at 13:13
  • is it working @MrunalShidurkar? – Rajesh Joshi Mar 30 '16 at 13:21
1

Is it possible that your SharePoint has MDS activated?

(You can most probably test that by reloading the page. If your script works on freshly loaded pages but not after "normal" navigation - check MDS...)

If MDS is active, you'll need to make sure that you register a namespace (using Type.registerNamespace) and possibly register your module-init (using window.RegisterModuleInit)

Wictor Wilén has a nice post on this.

1

Finally I got the solution Below code works fine for me

<scripts><asp:ScriptReference Path="<%$SPUrl:../../Scripts/FieldToHide.js%>"></asp:ScriptReference></scripts>

Note: Above code be placed inside asp:ScriptManager tag

0

You could simply edit your custom master page (ex. mymaster.html) with Sharepoint Designer.

and add the link to your script.

ex.

<script language="javascript" src="/StyleLibrary/scripts/yourscript.js"></script>

then publish your custom master page.

  • This solution is not working – Mrunal Shidurkar Mar 30 '16 at 13:28
  • did you debug with F12 on the browser to see if the script was downloaded? – Gyonder Mar 30 '16 at 13:45
  • script is downloading. But While navigating to list page it give 404 error for the same script. – Mrunal Shidurkar Mar 30 '16 at 13:47
  • so it means that you should check where the script is and what you wrote in src="". What do you have in src="" in the master page ? – Gyonder Mar 30 '16 at 13:49
  • This was actually my question. Script Path should be work on all pages – Mrunal Shidurkar Mar 30 '16 at 13:51
0

you can also add a script file to your master page this way.

Grab a file from the Farm Level site (root)

<SharePoint:ScriptLink ID="UniqueIdForYourFile22" Language="javascript" Name="NameOfYourScriptFile.js" OnDemand="true" runat="server" Localizable="false" />

You can also grab the file from the site collection level. This is from the SiteAsset.

<SharePoint:ScriptLink ID="UniqueIdForYourFile29" runat="server" Name="~sitecollection/SiteAssets/AngularJS/angular.js" Language="javascript" OnDemand="false" />

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.