How to Change Site Master page using JSOM in Sharepoint 2013/2016?

Hello Share pointers,

Here is the JSOM code to change SharePoint master page using Java script object model in Sharepoint 2013 and 2016.

var context;
var web;
var MasterPageUrl = ‘/_catalogs/masterpage/mycustom.master’;

context = new SP.ClientContext.get_current();
web = context.get_web();

web.set_customMasterUrl(MasterPageUrl);
web.set_masterUrl(MasterPageUrl);
web.update();

context.executeQueryAsync(function () {

alert(“Master Page is” + sMasterPageUrl);

}, function (sender, args) {

alert(“Error: ” + args.get_message());

});
}

Happy Sharepointing Folks 🙂

Leave a Reply

Your email address will not be published.