用于设置母版页的完美工作脚本:
$(document).ready(function () { jQuery('.cmdSet').click(function () {
var scriptBase = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/";
$.getScript(scriptBase + "sp.runtime.js", function () {
$.getScript(scriptBase + "sp.js", function () {
$.getScript(scriptBase + "sp.core.js", sharePointReady);
});
});
});
});
// create page-level variables to hold client context and web
var context;
var web;
var masterurl;
var site;
function sharePointReady() {
// assign values to page-level variables
context = new SP.ClientContext.get_current();
web = context.get_web();
// provide CSOM with instructions to load info about current web
context.load(web, 'ServerRelativeUrl');
web.set_customMasterUrl(L_Menu_BaseUrl + '/_catalogs/masterpage/seattle.master');
web.set_masterUrl(L_Menu_BaseUrl + '/_catalogs/masterpage/seattle.master');
web.update();
context.executeQueryAsync(function () {
alert("Starting Master Page Setting......");
masterurl = web.get_serverRelativeUrl() + "/_catalogs/masterpage/seattle.master";
alert(masterurl);
alert("Master Page is Set Successfully!!!");
}, function (sender, args) {
alert("Error: " + args.get_message());
});
}