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.
Sample Visualforce Page Code:
<apex:page id=”pg”>
<script src=”/support/console/51.0/integration.js”></script>
<script type=”text/javascript”>
var disableBool;
function fetchPrimaryTabId() {
sforce.console.getFocusedPrimaryTabId( showTabId );
}
function showTabId( result ) {
console.log( JSON.stringify( result ) );
console.log( ‘Enable Bool value is ‘ + disableBool );
sforce.console.disableTabClose( disableBool, result.id );
}
function disableTabCloseWithoutId() {
sforce.console.disableTabClose( true );
}
function enableTabCloseWithoutId() {
sforce.console.disableTabClose( false );
}
function disableTabCloseWithId() {
disableBool = true;
fetchPrimaryTabId()
}
function enableTabCloseWithId() {
disableBool = false;
fetchPrimaryTabId()
}
</script>
<apex:form >
<apex:commandButton value=”Enable Close” onclick=”enableTabCloseWithoutId();” reRender=”pg”/>
<apex:commandButton value=”Disable Close” onclick=”disableTabCloseWithoutId();” reRender=”pg”/>
<br/>
<apex:commandButton value=”Enable Close with Tab Id” onclick=”enableTabCloseWithId();” reRender=”pg”/>
<apex:commandButton value=”Disable Close with Tab Id” onclick=”disableTabCloseWithId();” reRender=”pg”/>
</apex:form>
</apex:page>
<script src=”/support/console/51.0/integration.js”></script>
<script type=”text/javascript”>
var disableBool;
function fetchPrimaryTabId() {
sforce.console.getFocusedPrimaryTabId( showTabId );
}
function showTabId( result ) {
console.log( JSON.stringify( result ) );
console.log( ‘Enable Bool value is ‘ + disableBool );
sforce.console.disableTabClose( disableBool, result.id );
}
function disableTabCloseWithoutId() {
sforce.console.disableTabClose( true );
}
function enableTabCloseWithoutId() {
sforce.console.disableTabClose( false );
}
function disableTabCloseWithId() {
disableBool = true;
fetchPrimaryTabId()
}
function enableTabCloseWithId() {
disableBool = false;
fetchPrimaryTabId()
}
</script>
<apex:form >
<apex:commandButton value=”Enable Close” onclick=”enableTabCloseWithoutId();” reRender=”pg”/>
<apex:commandButton value=”Disable Close” onclick=”disableTabCloseWithoutId();” reRender=”pg”/>
<br/>
<apex:commandButton value=”Enable Close with Tab Id” onclick=”enableTabCloseWithId();” reRender=”pg”/>
<apex:commandButton value=”Disable Close with Tab Id” onclick=”disableTabCloseWithId();” reRender=”pg”/>
</apex:form>
</apex:page>