getEnclosingTabId()

Returns the ID of the tab that contains the current Visualforce page, which may be a primary tab or subtab. This method will work if the call is made within a component enclosed within a subtab. This method is only available in API version 20.0 or later.

Syntax

sforce.console.getEnclosingTabId()

Arguments

Name Type Description
callback function JavaScript method that’s called upon completion of the method.

Sample Code–Visualforce

<apex:page standardController="Case">
    <A HREF="#" onClick="testCloseTab();return false">
        Click here to close this tab</A> 

    <apex:includeScript value="/support/console/64.0/integration.js"/>
    <script type="text/javascript">
        function testCloseTab() {
            //First find the ID of the current tab to close it
            sforce.console.getEnclosingTabId(closeSubtab);
        }
        
        var closeSubtab = function closeSubtab(result) {
            //Now that we have the tab ID, we can close it
            var tabId = result.id;
            sforce.console.closeTab(tabId);
        };
    </script>
</apex:page>

To see this example in action, click the custom link on a case. For more information, see Define Custom Buttons and Links in Salesforce Help.

Note

Response

This method is asynchronous, so it returns its response in an object in a callback method. The response object contains the following field:

Name Type Description
id string The ID of the current primary tab or subtab.