Skip to content

Instantly share code, notes, and snippets.

@sksnips
Last active March 28, 2016 04:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sksnips/5077450b2ad83cabda10 to your computer and use it in GitHub Desktop.
Save sksnips/5077450b2ad83cabda10 to your computer and use it in GitHub Desktop.
This JSOM code snippet enables the access to users to customize the master pages and page layouts in the current site collection level.
//Author: Shantha Kumar T
//Property used: SP.Site.allowMasterPageEditing (sp.js)
//Supports SharePoint 2010 + and SharePoint Online
function enableMasterPageAccess() {
var clientContext = new SP.ClientContext();
oSite = clientContext.get_site();
//The below line helps to enables the master page access
oSite.set_allowMasterPageEditing(true);
clientContext.load(oSite);
clientContext.executeQueryAsync(
Function.createDelegate(this, function() {
var siteInfo = '';
//The below line get the boolean value of master page editing is allowed on this site collection
if (oSite.get_allowMasterPageEditing())
siteInfo = 'MasterPage customization: Allowed';
else
siteInfo = 'MasterPage customization: Not Allowed';
alert(siteInfo.toString());
}),
Function.createDelegate(this, function(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}));
}
function injectMethod() {
enableMasterPageAccess();
}
ExecuteOrDelayUntilScriptLoaded(injectMethod, "sp.js");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment