SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have included some javascript in SharePoint master page, I need this javascript to have access to the opened list ID.

For example when I load Fields/AllItems.aspx

I need my JavaScript function to have access to the list: All Fields ID.

Notice there is no query string. I suppose I could extract the list name from the URL but as I'm trying to make it work on any site/list combination I was hoping there would be an easier way to extract the current opened list ID's GUID.

share|improve this question

At least two options are available to determine List Id on View page:

Option 1: SP.ListOperation.Selection Methods

SP.ListOperation.Selection.getSelectedList() Method gets the ID of the list being selected by the client user. The following example will return List Id in a View page.


var listId = SP.ListOperation.Selection.getSelectedList();

Option 2: spPageContextInfo client context

With every page is associated client context (_spPageContextInfo object), that object contains List Id when the View page is rendered. The following example demonstrates how to get List Id in View page.


//get current List Id in View page
var listId = _spPageContextInfo.pageListId;
share|improve this answer

Check out the ctx variable. There's lots of great info in there. In your case, what you need is:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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