0

I need to prevent a tab from closing on a condition (not necessarily unsaved data). Is there something I can do with the result object or other API to call to prevent the tab from closing?

sforce.console.getFocusedSubtabId(function (result) { 
     if (result.id) { 
        sforce.console.addEventListener(sforce.console.ConsoleEvent.CLOSE_TAB, function (result) { // what to do here }, { tabId : result.id }); 
     }
}); 
2

You can use the setTabUnsavedChanges method to check for and indicate that a tab has unsaved changes.

Documentation.

  • Thanks, I was not aware of that. Unfortunately, that is not exactly what I want to accomplish. I really want to prompt users with a different message such as "Are you sure you want to close this tab?" My application loads multiple tabs automatically and it's not convenient to re-open all the tabs. Warning them before closing the tab is what I want to accomplish. – Mark Lindell Feb 26 '15 at 18:18
  • Mark you can accomplish this using this method. If I am not mistaken SFDC will do it for you (warns the user about unsaved changes when they try to close it) or you can check for the result in JavaScript and add your own custom message. Did you give it a shot? – Richard N Feb 26 '15 at 18:20
  • Yes, I can't find a way to change the message. The API seems to be specific to unsaved changes. – Mark Lindell Feb 26 '15 at 18:25
  • That is interesting. In this case I wonder if the sforce.console.ConsoleEvent.CLOSE_TAB property can be used. – Richard N Feb 26 '15 at 18:32
0

In my opinion, Richard N. has probably the best answer for this.

Here's why:

Adding an event listener to the sforce.console.ConsoleEvent.CLOSE_TAB event will only allow you to get your listener called before the tab is closed. The tab will eventually closed irrespective of what you do in your callback.

By using setTabUnsavedChanges, you will allow a tab to enter a "dirty state", as shown by the * asterisk. A dirty state means that the tab has been edited. When closing the tab, an error message will be displayed, asking the user if they want to save the unsaved changes. As far as I know, we don't support changing the message in the dialog.

Hope that helps to clarify.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.