0

I am using this piece of code on a couple of sites within my SharePoint Online environment:

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function(){
    alert('test');
    //my code follows
});

Although, this code doesn't work on some pages (I don't get the alert)

I've checked in the browser, SP.js is actually loaded. Any ideas???

Gintas K
  • 1,227
  • 4
  • 19
  • 36

2 Answers2

0

Try this:

ExecuteOrDelayUntilScriptLoaded(function () {
alert('test');
   //code
}, "sp.js");
Viraj Gorajia
  • 1,659
  • 1
  • 13
  • 26
0

Just sorted this out.

I was comparing this site with other site where this code is working and I found out that the problem was this site feature.

Minimal Download Strategy

A technique that delivers a faster and more fluid page navigation experience, in pages and site templates that support it, by downloading and rendering only those portions of a page that are changing.

It was active on my site, so the script didn't work.

I switched it off and everything is fine now.

Strange thing is that I'm the only one developing on this Site Collection and I didn't modify any of the site features so far.

Gintas K
  • 1,227
  • 4
  • 19
  • 36