Javascript to capture when a user closes or leaves sap bsp html page









This page is just to demonstrate that the code implemented via the capture browser closed topic works and even though your browser has closed, the user left the page or refreshed it the onunload/onbeforeunload fucntionality was processed correctly to call this URL!!!

Now that you have seen it working you can replace the URL call within the JavaScript which uses the "window.open(..." command with a call to a standard Javascript function or an Ajax call call to perform additional ABAP code. For example when the browser is closed you may need to release any SAP database locks you may have created in the application.


function HandleOnClose()
        {
          //after window has closed, note any alert that you put in here may not be displayed
          if (myclose==true)
          {
            alert("Window is closed!!");
            releaseLock();
          }
        }