I want to run some javascript (not jQuery) after the page loads in SharePoint. What method should I include my script in?


Many things happen on page after $(document).ready(). 2013 does provide a few options to execute javascript function after page loads.

1) Script on Demand: (load a js file then execute you code:

function stuffThatRequiresSP_JS(){
    //your code
SP.SOD.executeFunc("sp.js", stuffThatRequiresSP_JS) ;

2) Delay until loaded (wait for a js file, then run):

function stuffToRunAfterSP_JS(){
    //your code

3) load after other stuff finishes:

function runAfterEverythingElse(){
    // your code


  1. executeFunc: http://msdn.microsoft.com/en-us/library/ff409592(v=office.14).aspx

  2. ExecuteOrDelayUntilScriptLoaded: http://msdn.microsoft.com/en-us/library/ff411788(v=office.14).aspx

  3. For _spBodyOnLoadFunctionNames: source

| improve this answer | |
  • The function $(document).ready(). is jQuery.. isn't it? What is the javascript equivalent? – Martin Muldoon Oct 31 '18 at 13:05
  • Yes, the other 3 options given in answer are using javascrip and not jquery. – Ganesh Sanap Oct 31 '18 at 13:07
  • Yes.. just waiting 3 minutes so they will let me :-) – Martin Muldoon Oct 31 '18 at 13:12
  • One last question Ganesh... What is the javascript equivalent of this jQuery function? var refiner = $getClientControl(document.getElementById("MSOZoneCell_WebPartWPQ4")); – Martin Muldoon Oct 31 '18 at 13:57
  • Where are you using this $getClientControl function? And for what? – Ganesh Sanap Oct 31 '18 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.