+ Start a Discussion
Lukasz Z.Lukasz Z. 

Service Cloud Console - Prevent close tabs

Hi All,

I'm working with the task related to closing tabs in service cloud console.
I handle actions when user close window or browser tab using this part of code:

 

<script type="text/javascript">
	var validNavigation = false;
 
        function wireUpEvents() {
        
        //get current url
        var linkUrl = window.location.href;

         var dont_confirm_leave = 1; //set dont_confirm_leave to 1 when you want the user to be able to leave withou confirmation
          var leave_message = 'You sure you want to leave page: '+ linkUrl +'?'
          function goodbye(e) {
          //alert(linkUrl);
            if (!validNavigation) {
              if (dont_confirm_leave!==0) {
                if(!e) e = window.event;
                //e.cancelBubble is supported by IE - this will kill the bubbling process.
                e.cancelBubble = true;
                e.returnValue = leave_message;
                //e.stopPropagation works in Firefox.
                if (e.stopPropagation) {
                  e.stopPropagation();
                  e.preventDefault();
                }
                //return works for Chrome and Safari
                return leave_message;
              }
            }
          }
          window.onbeforeunload=goodbye;
         
          // Attach the event keypress to exclude the F5 refresh
          jQuery(document).bind('keypress', function(e) {
            if (e.keyCode == 116){
              validNavigation = true;
            }
          });
         
          // Attach the event click for all links in the page
          jQuery("a").bind("click", function() {
            validNavigation = true;
          });
         
          // Attach the event submit for all forms in the page
          jQuery("form").bind("submit", function() {
            validNavigation = true;
          });
         
          // Attach the event click for all inputs in the page
          jQuery("input[type=submit]").bind("click", function() {
            validNavigation = true;
          });
         
        }
         
        // Wire up the events as soon as the DOM tree is ready
        jQuery(document).ready(function() {
          wireUpEvents();
        });
	 </script>  

 

But I have problems with closing tabs in service console. Any ideas how I can handle this?

 

Regards,

Lukasz

 

 

[EDIT]

We can do this invoking Service Cloud Console Method:

function tabUnsavedJS(){
           sforce.console.setTabUnsavedChanges(true, displayResult);
      }

 function displayResult(result) {
             if (result.success) {
                 alert('Tab status has been successfully updated');
             } else {
                 alert('Tab status couldn’t be updated');
             }
      }

 After this Salesforce will show warning message when user will close concole tab,

mbforcembforce
Hi Lukasz,

I am working on similar requirement where I want to prevent user from closing a subtab if one of the field on that VF page is blank,
when user close the subtab by keeping a field blank I want to show a popup warning to user, and page should not be closed.

I have tried to achieve that using Javascript but it is not working.

Can you please help me if you know how to achieve this.

Thanks,
Manish
Rahul SahayRahul Sahay
Hi Lukasz, Manish,

I am stuck in similar kind of requirement. I need to prevent close tab based on some condition. Please help me !

Thanks, 
- Rahul
sfdcAnonsfdcAnon
Hi Rahul, Lukasz's code snippet using - sforce.console.setTabUnsavedChanges(true, displayResult); answers how to do this. What's the gap preventing it being a solution for you?

Alternatively you can also listen for the the CLOSE_TAB event and react to it. See here - http://www.salesforce.com/us/developer/docs/api_console/Content/sforce_api_console_methods_events.htm

Hope that helps.