0

My users are reporting some strange behaviour with some pages created with the same custom layout pages and custom master page in a sp2013 publishing site

Essentially, I have function referenced in the master page that does stuff using CSOM on all my pages ( see below). ...Has worked fine till now.

for example I have created 2 welcome pages from the same custom layout page and master page.

/site/Pages/home.aspx .... works perfectly

/site/Pages/Home2.aspx does not fire the function below in the document ready which I think is related to the load state of "sp.js" . Just to confuse things if I check out Home2.aspx .... the ExecuteOrDelayUjtilLoaded fires! I checkin and publish the script stops firing.... Aaaahhhhhhhh!!!!

  $(document).ready(function() {

  ExecuteOrDelayUntilScriptLoaded(function () {
  /* your code here whch has to be run after the CSOM runtime gets loaded */
  MyFuction();

  }, "sp.js");
2

I do remember having a similar problem to this in the past. The SP.js never loaded on Published pages.

Because it's not loaded, the file is not able to call SP.SOD.notifyScriptLoadedAndExecuteWaitingJobs and hence the call to ExecuteOrDelayUntilScriptLoaded will never run.

In order to load the file from the SOD library, use the following:

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function() { //whatever function here; });

This function 'loads' the script if it is not already loaded. This applies to the scripts already in the SOD dictionary.

Other option is to load the file directly from the layouts directory.

  • this has worked like a charm. It was weird with the old code it worked for same home but when I create another home page it didn't work. I will let the users on this tomorrow. – westerdaled Jul 20 '14 at 18:18
0

Try removing the jquery document ready function and place the execute or delay directly in the script tag. I thing the issue here is the order in which your functions fire...

  • The issue I have is I want to change the CSS after the page is loaded which is why I went for document ready. As @Hughwood warned me after he reviewed my approach, the doc ready code won't work with MDS. – westerdaled Jul 20 '14 at 18:21

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.