Newer Version Available

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

closeTab()

Closes a specified primary tab or subtab. Note that closing the first tab in a primary tab closes the primary tab itself. This method is only available in API version 20.0 or later.

Syntax

1sforce.console.closeTab(id:String, (optional) callback:Function)

Arguments

Name Type Description
id string ID of the primary tab or subtab to close.
callback function For API version 35.0 or later, the JavaScript method that’s called upon completion of the method.

Sample Code API 20.0 or Later–Visualforce

1<apex:page standardController="Case">
2    <A HREF="#" onClick="testCloseTab();return false">
3           Click here to close this tab</A> 
4
5    <apex:includeScript value="/support/console/42.0/integration.js"/>
6    <script type="text/javascript">
7        function testCloseTab() {
8            //First find the ID of the current tab to close it
9            sforce.console.getEnclosingTabId(closeSubtab);
10        }
11        
12        var closeSubtab = function closeSubtab(result) {
13            //Now that we have the tab ID, we can close it
14            var tabId = result.id;
15            sforce.console.closeTab(tabId);
16        };
17    </script>
18</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 the Salesforce help.

Note

Response

None

Sample Code API Version 35.0 or Later–Visualforce

1<apex:page standardController="Case">
2    <A HREF="#" onClick="testCloseTab();return false">
3           Click here to close this tab</A> 
4
5    <apex:includeScript value="/support/console/42.0/integration.js"/>
6    <script type="text/javascript">
7         var callback = function () {
8             if (result.error) {
9		        alert("Error message is " + result.error);
10             }
11         };
12        function testCloseTab() {
13            //First find the ID of the current tab to close it
14            sforce.console.getEnclosingTabId(closeSubtab);
15         }
16
17        var closeSubtab = function closeSubtab(result) {
18            //Now that we have the tab ID, we can close it
19            var tabId = result.id;
20            sforce.console.closeTab(tabId, callback);
21        };
22    </script>
23</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 the 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 fields:

Name Type Description
success boolean true if the tab was re-opened, false otherwise.
error string Error message if the tab couldn’t be closed.

When using Firefox, we recommend that you don't call closeTab() on a tab with an active alert box because the browser may not load properly.

Tip