In this blog we will try to get current site title, web tile and any intermediate web title using CSOM. You can go deep down if you have further requirement for these objects.
Here is the basic function to get site details:
Sample code:
var currSiteTitle; // site collection details
var currWebTitle; // get sub site details
var parentWebTitle; // get any intermediate site details
$(document).ready(function() {
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function() {
getWebTitle();
});
});
function getWebTitle() {
var context = new SP.ClientContext.get_current();
var site = context.get_site();
var web = context.get_web();
context.load(site);
context.load(web);
var parentInfo = web.get_parentWeb();
context.load(parentInfo);
context.executeQueryAsync(function() {
console.log(site.get_title());
console.log(site.get_url());
console.log(web.get_title());
console.log(web.get_url());
console.log("Intermediate site value: " + parentInfo.get_title());
currSiteTitle = site.get_title();
currWebTitle = web.get_title();
parentWebTitle = parentInfo.get_title();
},
function(sender, args) {
console.log(args.get_message());
}
);
}
Original Source:
- https://msdn.microsoft.com/en-us/library/office/jj246780.aspx
- https://msdn.microsoft.com/en-us/library/office/jj246877.aspx
- https://sharepoint.stackexchange.com/questions/175217/get-parent-web-of-a-subsite-using-jsom-in-sharepoint-2013