3

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 2

1

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');
7
  • It has not been requested or the request has not been executed. It may need to be explicitly requested?
    – Hannes
    Dec 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 its a publishing site. Does it matter?
    – Hannes
    Dec 4, 2014 at 15:24
  • Yes. In that case we should get the Publishing Web and then use the DefaultPage Dec 4, 2014 at 15:25
  • @Hannes I have edited my answer. Dec 4, 2014 at 15:53
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.