Show TOC

Appendix: JavaScript Code for Session TerminationLocate this document in the navigation structure

Use

The following is sample code used to trigger closure of an SAP session when a user logs off the company portal.

            <html>
        <head>
                <script>
                
                        var isLogoffFinalAllowed = true;
                        var logoffStartTime;                    
                        
                        function logoffPortal() {
//domain relaxation
                                document.domain = "tlv.sap.corp";
                                var epcm = document.frames['portalframe'].EPCM;
//this event is terminating the backend //sessions
                                epcm.raiseEvent
("urn:com.sapportals.portal:user",
 "logoff","");
                                logoffStartTime = (new Date).getTime(); 
                                window.setTimeout("logoffDelay()", "50");                               
                        }
                                                                                                                
                                        
//this method is waiting for the backend sessions to //be ended and then triggering portal log off
                        function logoffDelay()
                        {
                          var isLogoffDelayElapsed = 
  ((new Date).getTime() - logoffStartTime) > (60*1000);
                          if(isLogoffFinalAllowed || isLogoffDelayElapsed) { 
                             logoffFinalCall();
                          } else {
                             window.setTimeout("logoffDelay()","50"); 
                          }
                        }
                        
                        function logoffFinalCall()
                        {
                                document.getElementById('portalframe').src 
= "javascript: void(0);";
                                var logoffForm = document.
createElement("form");
                                var logoffParam = document.
createElement("input");
                                logoffParam.name = "logout_submit";
                                logoffParam.value = "true";
                                logoffForm.appendChild(logoffParam);
//this component is logging of the portal
logoffForm.action = "http://<HOST>:<PORT>/irj/servlet/prt/portal/prtroot/com.sap.portal.navigation.masthead.LogOutComponent";
                                logoffForm.method = "post";
                                logoffForm.target = "portalframe";
                                document.appendChild(logoffForm);
                                logoffForm.submit();    
                        }
                        

                        
                        
                </script>
        </head>
<!-- usage example - the logoff href is triggering logoff in the iFrame portal as well-->
        <body>
                <h5>DSM Test</h5>
                <br/>     
                        <a href="#" onclick="logoffPortal();">Logoff</a>
                <br/><br/><br/>               
<iframe id="portalframe" style="width: 95%; height: 600px;" name="portalframe" src="http://<HOST>:<PORT>/irj/portal/interop?NavigationTarget=navurl://631c127e4710538c99e4aeb58b928ec8=administrator@j_password=abcd1234"></iframe>
                
        </body>
</html>