+ Start a Discussion
Dippan PatelDippan Patel 

Close Previous tab in Console using javascript

Hi All, 

I am using visualforce page in lightning for creating a new record. In case of Lightning Console, the record gets saved and open up in a new tab, the current tab with the create record visualforce page remains as it is. 

Here is my sample code: 
<apex:commandButton action="{!customsave}" value="save"  onComplete = "testmethod();"> 

testmethod(){
    //get the record Id (format: "/recordid")
sforce.one.navigateToURL(recordid);
}


How do I close the current tab before the new tab is open? I tried salesforce's console - closeTab() but it doesn't seem to be working. 

Thank you!
AnudeepAnudeep (Salesforce Developers) 
Can you try the following code?. I don't think there isn't any alternative to closeTab() other than window.close() javascript method
 
<apex:page sidebar="false" showHeader="false" > 
   <apex:includeScript value="/support/console/33.0/integration.js"/> 
   <script type="text/javascript">     
     //Close tab in Console    
        var callCloseTab= function callCloseTab(result) {
            sforce.console.closeTab(result.id);
        }        
        function closeTab() {
                    sforce.console.getEnclosingTabId(callCloseTab);
                            }
//Close tab in Browser        
function closeWindow() {
                window.open('','_parent','');
                window.close();
            }
    </script>     
       <flow:interview name="Log_an_Account_Call" buttonLocation="bottom" /> 
     
       <button href="#" onClick="closeTab();return false">Close This Tab in the Finance Console</button> 
       <button href="#" onClick="closeWindow();return false">Close This Tab in your Browser</button>
     
    </apex:page>