Wednesday, September 4, 2013

SharePoint 2013: Links on Publishing Page do not work due to MDS (Miniaml Download Strategy)

We have a published page with a web part on it. Links inside this web part do not seem to work when the page is in "Published" mode. They do work as expected in edit mode when page is checked out and unpublished.
The reason is MDS (Minimal Download Strategy). Even if the feature is disabled script files in SharePoint 2013 are loaded only when required. Specially sp.js file.
So here is the solution. Put a script editor webpart on top of the controls and have the following script and then publish the page within a "script" block.
var clientContext;
var website;
// Make sure the SharePoint script file 'sp.js' is loaded before your
// code runs.
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);
// Create an instance of the current context.
function sharePointReady() {
    clientContext = SP.ClientContext.get_current();
    website = clientContext.get_web();
    clientContext.executeQueryAsync(onRequestSucceeded, onRequestFailed);
function onRequestSucceeded() {
function onRequestFailed(sender, args) {

No comments:

Post a Comment