In SP2013, how can I check if the current page is the default page of the current site using javascript object model or REST api?
Thanks
In SP2013, how can I check if the current page is the default page of the current site using javascript object model or REST api?
Thanks
At first get the current page from _spPageContextInfo
var currentPage = _spPageContextInfo.serverRequestPath
Now make a GET request in following end-point to get default or welcome page
_api/Web/RootFolder/WelcomePage
After getting the response, check if both are same.
PS: It works in team & publishing site both.
SP.SOD.executeFunc("SP.js", "SP.ClientContext", function() {
var currentPage = _spPageContextInfo.serverRequestPath
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/RootFolder/WelcomePage",
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
},
success: function(data) {
if (currentPage.indexOf(data.d.WelcomePage) > -1) {
console.log("Current page is default");
} else {
console.log("Current page is not default");
}
},
error: function(error) {
alert(JSON.stringify(error));
}
});
});
SP.SOD.executeFunc
is important, you are executing code on publishing site