Here is one way to change the master page of a SharePoint site using JSOM, I have tested this in O365 site but it should work with on-prem version of SharePoint as well. This code can be run on a script editor webpart and it works on the click of a html button control. <script src="/_layouts/15/SP.Runtime.js" type="text/javascript"></script> <script src="/_layouts/15/SP.js" type="text/javascript"></script> <script type="text/javascript"> function ChangeMasterPage() { var customMasterPage = "/_catalogs/masterpage/Custom.master"; var siteRelativeUrl = _spPageContextInfo.siteServerRelativeUrl; var clientContext; var currentWeb; SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () { clientContext = new SP.ClientContext.get_current(); currentWeb = clientContext.get_web(); currentWeb.set_customMasterUrl(siteRelativeUrl + customMasterPage); currentWeb.set_maste...
Practical insights into Microsoft 365 architecture, SharePoint Online, PowerShell automation, governance and security. Real world troubleshooting, technical solutions and lessons learned from enterprise IT environments.