Newer Version Available
disableTabClose()
Prevents a user from closing a tab or a subtab.
If the ID parameter doesn’t specify a tab, the enclosing tab is used. You can also use
this method to re-enable a tab that has been disabled. Available in API version
36.0 or later.
Syntax
1sforce.console.disableTabClose(disable:boolean, (optional) tabId:String, (optional) callback:Function)Arguments
| Name | Type | Description |
|---|---|---|
| disable | boolean | Specifies whether to disable the tab. If true, the user can’t close the tab. If false, the user can close the tab. |
| tabId | string | The tabId for the tab to enable or disable. Use false to automatically select the enclosing tab or subtab without needing to specify a tabId. The enclosing tabId can’t be inferred when this call is made from outside a sidebar component. For example, if you call this method from a footer widget, specify the tabId. If the tabId is for a “Details” subtab of a primary tab, the primary tabId is used instead. |
| callback | function | JavaScript method that’s called upon completion of the method. The callback is passed a response object. See response information below. |
Sample Code–Visualforce
1<apex:page >
2<html>
3 <head>
4 <title>Disable close Tab on Load</title>
5
6 <!-- Service Console integration API library -->
7 <script src="/support/console/56.0/integration.js"></script>
8
9 <!-- Callback functions to handle tab events -->
10 <script type="text/javascript">
11
12 function displayResultsCallback(result){
13 var resDiv = document.getElementById("eventResults");
14 resDiv.innerHTML = JSON.stringify(result);
15 }
16
17 // For use within a tab's sidebar (you don't need tab ID)
18
19 function testDisableTabCloseTrueWithoutId() {
20 sforce.console.disableTabClose(true, false, displayResultsCallback);
21 }
22
23 function testDisableTabCloseFalseWithoutId() {
24 sforce.console.disableTabClose(false, false, displayResultsCallback);
25 }
26
27 // For use anywhere (you need the tab ID)
28
29 // Note: Your tab ID might be different than the one used here.
30 // You can get the tab ID many different ways,
31 // including sforce.console.getEnclosingTabId().
32 // See the documentation for details.
33 function testDisableTabCloseTrueWithId() {
34 var tabId = window.prompt("Enter the tab ID","scc-pt-0");
35 sforce.console.disableTabClose(true, tabId, displayResultsCallback);
36 }
37
38 function testDisableTabCloseFalseWithId() {
39 var tabId = window.prompt("Enter the tab ID","scc-pt-0");
40 sforce.console.disableTabClose(false, tabId, displayResultsCallback);
41 }
42
43 </script>
44 </head>
45
46 <body>
47 <h1>Disable Tab Close Examples</h1>
48 <br/><br/>
49
50 <h2>API Callback Result</h2>
51 <br/>
52
53 <code><div id="eventResults" /></code>
54 <br/>
55
56 <h2>With No Tab ID</h2>
57 <p>The tab ID will be auto-detected by context, or the event will fail.</p>
58
59 <ul>
60 <li><a href="#" onClick="testDisableTabCloseTrueWithoutId();return false;">
61 Disable closing for the enclosing tab</a></li>
62
63 <li><a href="#" onClick="testDisableTabCloseFalseWithoutId();return false;">
64 Re-enable closing for the enclosing tab</a></li>
65 </ul>
66
67 <h2>With Tab ID Provided</h2>
68 <p>When the event context doesn't have a detectable tab ID, you can
69 supply it yourself.</p>
70
71 <ul>
72 <li><a href="#" onClick="testDisableTabCloseTrueWithId();return false;">
73 Disable closing for a specific tab (via tab ID)</a></li>
74
75 <li><a href="#" onClick="testDisableTabCloseFalseWithId();return false;">
76 Re-enable closing for a specific tab (via tab ID)</a></li>
77 </ul>
78
79 </body>
80</html>
81</apex:page>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 action completed successfully, false otherwise. |
| message | string | If the action completed successfully, message contains the affected tabId. If the action failed, message contains the error message. |