How to retrieve the information if we're currently in a web, list or document library?

Oct 13, 2014 at 3:47 PM
Hi Marc,

currently i'm using $().SPServices.SPListNameFromUrl(); to check if we're currently in a list or document library.

function validScope() {
var listName = null;
    listName = $().SPServices.SPListNameFromUrl();
    //retrieve ServerTemplate to check if we're in a document library
catch (err) {
    return false;

if (listName) {
    return true;

My expectation was, that SPListNameFromUrl returns null, when navigating out of a list scope, but instead i retrieve the following error from SPServices:

Uncaught TypeError: Cannot read property 'length' of undefined jquery.SPServices-2014.01.min.js:21am.fn.SPServices.SPListNameFromUrl jquery.SPServices-2014.01.min.js:21

Do you think i'm doing something wrong or is there a better approach to check this?

with kind regards

Oct 15, 2014 at 1:25 PM

It looks like a bug to me. I'll get a fix into the next alpha. In the meantime, you can check the _spPageContextInfo.pageListId variable in 2010 or 2013. It will be undefined if you are not in a list context.

Oct 15, 2014 at 1:26 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.