Thursday, May 23, 2013

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.


1 comment:

MaqsoodAshiq said...

Thanks for saving my time!!