Using JavaScript in custom master page for SharePoint 2013 that uses SP.js.

Hi,

We recently had a requirement to show no of listitems on a particular list on every page within the site. So we decided to use the JavaScript that does so in our custom master page itself.

This is how we got it working

Adding the SharePoint script link that refers to the SP.js file in our custom html master page.

<!–MS:<SharePoint:ScriptLink ID=”ScriptLink21″ Name=”sp.js” runat=”server” OnDemand=”false” LoadAfterUI=”true” Localizable=”false”>–>
<!–ME:</SharePoint:ScriptLink>–>

And then executing our script using the following method i.e. after SP.js is loaded

function GetCount() {

// code that uses CSOM to get the count

}


ExecuteOrDelayUntilScriptLoaded(GetCount, “sp.js”);

Hope it helps.


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

1 thought on “Using JavaScript in custom master page for SharePoint 2013 that uses SP.js.”

Share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s