I want to run some JavaScript (not jQuery) after the page loads in SharePoint.
What method should I include in my script?
Many things happen on page after $(document).ready()
. SharePoint 2013 does provide a few options to execute JavaScript function after page loads.
Script on Demand (load a .js
file then execute you code):
function stuffThatRequiresSP_JS(){
//your code
}
SP.SOD.executeFunc("sp.js", stuffThatRequiresSP_JS) ;
Delay until loaded (wait for a .js
file to load, then run):
function stuffToRunAfterSP_JS(){
//your code
}
ExecuteOrDelayUntilScriptLoaded(stuffToRunAfterSP_JS, "sp.js");
Run function after other stuff finishes loading:
function runAfterEverythingElse(){
// your code
}
_spBodyOnLoadFunctionNames.push("runAfterEverythingElse");
Sources:
executeFunc
: http://msdn.microsoft.com/en-us/library/ff409592(v=office.14).aspx
ExecuteOrDelayUntilScriptLoaded
: http://msdn.microsoft.com/en-us/library/ff411788(v=office.14).aspx
For _spBodyOnLoadFunctionNames
: source
$getClientControl
function? And for what?
Commented
Oct 31, 2018 at 14:04