Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
17
rated 0 times [  22] [ 5]  / answers: 1 / hits: 19662  / 12 Years ago, thu, july 5, 2012, 12:00:00

I have a custom JS script which I load into SharePoint and have problems to get my init method executed after SP is finished with its own initializing.



_spBodyOnLoadFunctionNames



I tried the official way first and added my function name to the list of executed functions after body load with _spBodyOnLoadFunctionNames.push(myInitMethod); but that does not fire on every page load, I can't rely on that.



ExecuteOrDelayUntilScriptLoaded



Then I tried to use ExecuteOrDelayUntilScriptLoaded(myInitMethod, sp.js); function but it does not fire on every page load either.



Both ways work - but not every time. I assume that my script is loaded sometimes before the SP is initialized. This happens mostly on Chrome but on IE as well.



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






Note: There is an interesting behaviour when the page is loaded and the SP object is not fully initialized (the registered functions in ExecuteOrDelayUntilScriptLoaded has not been called): As soon as I click on the Navigate Up anchor in the page (where you can see the hiarchy of the subsites) the following files gets loaded and my init function (registered in ExecuteOrDelayUntilScriptLoaded) gets called!




  • core.debug.js

  • sp.core.debug.js

  • ScriptResx.ashx

  • sp.ui.dialog.debug.js

  • sp.runtime.debug.js

  • sp.debug.js



So everything is fine after that click - but why not on pageload as it should be?


More From » sharepoint

 Answers
62

It seems that this behaviour is related to some issues between SP 2010 and Google Chrome - I don't have this issues on other browsers.


[#84454] Wednesday, July 4, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
austonjuancarlosb

Total Points: 238
Total Questions: 89
Total Answers: 99

Location: Chad
Member since Mon, Dec 5, 2022
1 Year ago
;