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.
<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
<lightning:workspaceAPI aura:id="workspace" />
<lightning:button label="Get Enclosing Tab Id" onclick="{! c.handleGetEnclosingTabId }" />
</aura:component>
This is the controller code. The handleGetEnclosingTabId action returns the ID of the enclosing workspace tab.
({
handleGetEnclosingTabId : function(component, event, helper) {
var workspaceAPI = component.find("workspace");
workspaceAPI.getEnclosingTabId().then(function(tabId) {
console.log(tabId);
})
.catch(function(error) {
console.log(error);
});
}
})