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???

4

2 Answers 2

0

Try this:

ExecuteOrDelayUntilScriptLoaded(function () {
alert('test');
   //code
}, "sp.js");
2
  • Doesn't alert anything :/ The strange thing is, I have some buttons within the page, when I click on them, I get the alert
    – Gintas K
    Jun 1, 2016 at 7:56
  • Have you checked syntax is correct. Alert without sp code and check. Jun 1, 2016 at 8:20
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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