Execute JavaScript function after SharePoint initialization

I have a custom JS script that I upload to SharePoint, and I am having problems getting my init method to execute after the SP completes with its own initialization.

_spBodyOnLoadFunctionNames

First I tried the "official" method and added my function name to the list of executable functions after loading the body with _spBodyOnLoadFunctionNames.push("myInitMethod");, but this does not work every time the page loads, I can not rely on it.

ExecuteOrDelayUntilScriptLoaded

Then I tried to use the function ExecuteOrDelayUntilScriptLoaded(myInitMethod, "sp.js");, but it does not work every time the page loads.

Both methods work - but not every time. I assume that my script sometimes loads before when the SP is initialized. This happens mainly in Chrome, but also in IE.

How can I make sure my script is executed when the SP is ready?


Note . There is an interesting behavior when loading the page, and the SP object is not fully initialized (the registered functions in ExecuteOrDelayUntilScriptLoaded were not called): as soon as I click on the "Navigate Up" button on the page (where you can see the sub-site hyarchy) the following files are loaded, and my function init (registered in ExecuteOrDelayUntilScriptLoaded) is being called!

  • core.debug.js
  • sp.core.debug.js
  • ScriptResx.ashx
  • sp.ui.dialog.debug.js
  • sp.runtime.debug.js
  • sp.debug.js

, - pageload, ?

+5
3

, SP 2010 Google Chrome - .

+4
+4

, , JavaScript , sp.js.

, , , , () SharePoint . Google Chrome, ( IE). , - :

if (typeof(_spBodyOnLoadWrapper)!='undefined'){_spBodyOnLoadWrapper();}

$(document).ready().

And thanks for the answer to my question :)

+2
source

All Articles