4

Is there a better way of testing if the current ASPX page is a List (or Library) page?

I now have:

if(
     !( 
       document.location.pathname.indexOf('/Forms/')<0 
        && 
       document.location.pathname.indexOf('/Lists/')<0
      )
  ){
     //is a page from a List or Library
   }
2
  • Hint: Look at the JS object ctx. It will be present on any page that contains a list view. Undefined if not. Not a complete answer to your question though hence adding as a comment. Commented Mar 11, 2016 at 16:13
  • ctx is available on any page with a ListViewWebPart, including the pages (eg. from the SitePages library) I need to exclude. Commented Mar 11, 2016 at 19:03

1 Answer 1

3

You could check the current list base template ID using JSOM. Page Library is 850 and it's not listed in the MS ref below.

var context = SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getById(_spPageContextInfo.pageListId);

context.load(list);


context.executeQueryAsync(
   function() {
        alert(list.get_baseTemplate());
   },
   function(){
    alert('error')
   }
  );

_spPageContextInfo.pageListId gives you the current page's list ID

https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splisttemplatetype.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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