I want to hide a "div" from all startpages/welcomepages. But I cant just compare "start.aspx" and my url parameter cause sometimes the page "start.aspx" isn't there in the url. Is there a way to know if I'm on a "startpage" or not using javascript?
2 Answers
SPWeb
has RootFolder
which internally has WelcomePage
property. You can use that to get this information
var clientContext = new SP.ClientContext.get_current();
var spWeb = clientContext.get_web();
var rootFolder = spWeb.get_rootFolder();
clientContext.load(rootFolder, 'WelcomePage');
clientContext.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this, onQueryFailed));
function onQuerySucceeded() {
alert(rootFolder.get_welcomePage());
}
function onQueryFailed(sender, args) {
alert('error');
}
In case of publishing web
var web = context.get_web();
var pubWeb = SP.Publishing.PublishingWeb.getPublishingWeb(context, web);
context.load(pubWeb, 'DefaultPage');
-
It has not been requested or the request has not been executed. It may need to be explicitly requested?– HannesDec 4, 2014 at 15:10
-
Not sure. Its working perfectly on my SP2013. By the way is it a publishing site? Dec 4, 2014 at 15:17
-
-
Yes. In that case we should get the
Publishing Web
and then use theDefaultPage
Dec 4, 2014 at 15:25 -
Thanks for the help, unfortunately it didnt work for me since there where something wrong with my SP.Publishing reference.
Instead I fixed it with this code:
$(document).ready(function () {
if (window.location.href.indexOf("_layouts") > -1) {
$(".ms-breadcrumb-top").show()
}
else {
$(".ms-breadcrumb-top").hide();
}
}
All pages accept welcomepages are located in the _layouts for me so I'll just hide my element if it's not in the _layouts folder. Works like a charm so far.