Newer Version Available

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

getTabURL() for Lightning Experience

Returns the URL of the specified tab.

Arguments

Name Type Description
tabId string ID of the tab for which to retrieve the URL.
callback function JavaScript method called upon completion of the method. Returns the URL of the specified tab.

Sample Code

This component has a button that, when pressed, opens a tab and uses the getTabURL() method to print the new tab’s URL to the developer console.

Component code:

1<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
2    <force:workspaceAPIAccess aura:id="workspace" />
3    <lightning:button label="Get Opened Tab URL" onclick="{! c.getOpenedTabURL }" />
4</aura:component>

Controller code:

1({
2    getOpenedTabURL : function(component, event, helper) {
3        var workspaceAPI = component.find("workspace");
4        workspaceAPI.openTab({
5            url: '#/sObject/001R0000003HgssIAC/view',
6            focus: true, 
7            callback : function(error, response) { 
8                workspaceAPI.getTabURL({
9                    tabId : response,
10                    callback : function(error, response){
11                        console.log(response); 
12                    }
13                });
14            }
15        });
16    }
17})

The relative URL used in this example is a placeholder. To try this example yourself, use a relative URL with a record ID from your org.

Note

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
url string The URL of the specified tab.