Issue with javascript / jquery not firing on a SharePoint 2013 page or masterpage?

I just spend a few hours analyzing why my Javascript/jQuery was not firing on my masterpage. Everything was good, I was down to using the simplest of code:

_spBodyOnLoadFunctions.push(function() { alert(“test”); });

No pop-up. It was in my source code. No script errors. Nothing. Silent. Dead.
Was there something wrong? Should I use document.ready ? Ofcourse not.

Once again, Elio Struyf came to the rescue. He asked me if the “Minimal Download Strategy” feature was enabled. Yes it was, I replied with a frown.

Apparantly, when you put scripts in your masterpage with the MDS feature enabled, things go horribly wrong. So, turn it off and see your javascript or jQuery running on the page!

About: Marijn

Marijn Somers (MVP) has over 12 years experience in the SharePoint world, starting out with SP2007. Over the years the focus has grown to Office 365, with a focus on collaboration and document management. He is a business consultant at Balestra and Principal Content Provider for "Mijn 365 Coach" that offers dutch employee video training. His main work tracks are around user adoption, training and coaching and governance. He is also not afraid to dig deeper in the technicalities with PowerShell, adaptive cards or custom formatting in lists and libraries. You can listen to him on the biweekly "Office 365 Distilled" podcast.

%d bloggers like this: