+ Start a Discussion
shiva pendemshiva pendem 

How to detect window Close Event in Vf page

HI Guys,

We are using  partner communities . So if the User login  by entering the credentials and when user logouts i need to perform some action. this is fine. But when user closes the window directly i need to perform same action which performs while logout. Please let me know how to detect the window close event and perform the actions in apex class . 

please advise us.

Mudasir WaniMudasir Wani
Hi Shiva,

It can be done Have a look on sample below script code.
It will run evertime a window is closed.
See if you can fire some remote action using salesforce Remoting.

Include below code in your page

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    function() { 
      var actionValue = confirm("Do you really want to close?");
        if(actionValue ==true){
            alert('close window');
            alert('Do not close window');
      return actionValue;

//Java script remoting help

Please mark this as solution if this solves your problem, So that if anyone has this issue this can help.