get currently selected list in javascript on load - sharepoint 2010

Necros picture Necros · Jun 21, 2011 · Viewed 9k times · Source

I'm currently trying to find out, how to get a reference to currently selected list in sharepoint from javascript. I can get it if I know the title, or id, but I want it to get the list dynamically depending on where the user is. I have this code (in my modal dialog):

ExecuteOrDelayUntilScriptLoaded(init, 'sp.js');

function init() {
    var context = SP.ClientContext.get_current();
    var web = context.get_web();
    var list = web.get_lists().getById(SP.ListOperation.Selection.getSelectedList());
}

The problem is that SP.ListOperation.Selection.getSelectedList() returns null. There is probably some other script I need to wait for - but which one?

Answer

Necros picture Necros · Jun 28, 2011

I figured it out. SP.ListOperation.Selection.getSelectedList() doesn't work inside of a modal dialog. I needed to pass list ID from the parent window.