Wednesday, 22 February 2012

Load SharePoint JavaScript Libraries on SharePoint CEWP

I spent 4 hours wondering why my SharePoint code did not run automatically when I did a _spBodyOnLoadFunctionNames but works when I did an onclick.

The reason behind this was that the SharePoint javascript Libraries have not been loaded fully when SP. functions were called, thus nothing happened, that is for example SP.ClientContext did not exist yet.



_spBodyOnLoadFunctionNames.push("LoadLastURL");

function LoadLastURL()
{
var myQueryString = "1";

var myContext = new SP.ClientContext.get_current();
...
}



The solution was simple, I just have to do the following





SP.SOD.executeOrDelayUntilScriptLoaded(LoadLastURL, 'SP.js');


function LoadLastURL()
{
...sharepoint javascript functions ....
}

No comments:

Post a Comment