SharePoint 2013: Working with sp.js files and Publishing pages

So you are trying to write Javascript code in SharePoint 2013 and want to load the sp.js file before your custom function is called. And for that you have used.

ExecuteOrDelayUntilScriptLoaded(“your javascript function”, "sp.js");

But it’s not working. Sad, isn’t it ?

The reason is that, with SharePoint 2013 publishing pages the above syntax doesn’t work. You need to register using the below syntax

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', “your javascript function”);

I struggled 2 hours to find this MSDN article which showed me the right way.
Advertisements

One thought on “SharePoint 2013: Working with sp.js files and Publishing pages

Leave a Reply

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s