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

 www.mypage.com/codev/_layouts/15/start.aspx#/Lists/All 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.

2 Answers 2


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;

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


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.