Newer Version Available

This content describes an older version of this product. View Latest

isSubtab() for Lightning Experience

Checks whether a tab is a subtab.

Arguments

Name Type Description
tabId string ID of the tab.
callback function JavaScript method called upon completion of the method. Returns true if the tab is a subtab, false otherwise.

Sample Code

This component has a button that checks whether the foucsed tab is a subtab and opens a modal with the answer.

Component code:

1<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
2    <force:workspaceAPIAccess aura:id="workspace" />
3    <lightning:button label="Is the Focused Tab a Subtab?" onclick="{! c.isFocusedTabSubtab }" />
4</aura:component>

Controller code:

1({
2    isFocusedTabSubtab : function(component, event, helper) {
3        var workspaceAPI = component.find("workspace"); 
4        workspaceAPI.getFocusedTabInfo({
5            callback : function(error, response){
6                workspaceAPI.isSubtab({
7                    tabId : response.tabId, 
8                    callback : function(error, response){
9                        if (response){
10                            confirm("This tab is a subtab.")
11                        } 
12                        else {
13                            confirm("This tab is not a subtab.")
14                        }; 
15                    }
16                }); 
17            }
18        });
19    }
20})

Response

This method is asynchronous, so it returns its response in a callback method, in an object that contains the following field.
Name Type Description
success boolean Returns true if the tab is a subtab, false otherwise.