Newer Version Available
getEnclosingTabId() for Lightning Experience
To retrieve the enclosing tab ID with LWC, see EnclosingTabId context wire adapter.
Arguments
Aura Components Sample Code
This component has a button that, when clicked, retrieves the enclosing tab ID.
This is the component code. The lightning:workspaceAPI component provides access to Lightning console methods. When clicked, the lightning:button base component executes the handleGetEnclosingTabId action in the component’s client-side controller.
1<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
2 <lightning:workspaceAPI aura:id="workspace" />
3 <lightning:button label="Get Enclosing Tab Id" onclick="{! c.handleGetEnclosingTabId }" />
4</aura:component>This is the controller code. The handleGetEnclosingTabId action returns the ID of the enclosing workspace tab.
1({
2 handleGetEnclosingTabId : function(component, event, helper) {
3 var workspaceAPI = component.find("workspace");
4 workspaceAPI.getEnclosingTabId().then(function(tabId) {
5 console.log(tabId);
6 })
7 .catch(function(error) {
8 console.log(error);
9 });
10 }
11})