Jump to content

Kill a session when browser is closed


leo-veio

Recommended Posts

Hi,

 

Put this code in MainForm->ExtEvents->OnBeforerender :

  window.onbeforeunload = function() {
         ajaxRequest(sender, 'SessionClosed', [] );
         alert("Session Closed"); // You can remove this line. only for test
  };

 

And put this code on MainForm->OnAjaxEvent :

 

  If SameText( EventName, 'SessionClosed' ) Then
  Begin
    UniSession.Terminate( );
    UniSession.UniApplication.Terminate( );
  End;

 

Work on FF, Chrome, IE

 

Regards

  • Upvote 5
Link to comment
Share on other sites

Hi, All

 

It's work just when MainFormDisplayMode  = mfWindow !!!

 

it's not work with MainFormDisplayMode  = mfPage !!!

 

 

How can I implement it on MainFormDisplayMode  = mfPage ? :(

 

 

Thanx

Maher

Link to comment
Share on other sites

Hi, All

 

It's work just when MainFormDisplayMode  = mfWindow !!!

 

it's not work with MainFormDisplayMode  = mfPage !!!

 

 

How can I implement it on MainFormDisplayMode  = mfPage ? :(

 

 

Thanx

Maher

 

Hi,

No problem,

Put this code in :

MainForm->ClientEvents->ExtEvents->1-Ext.form.formPanel->onBeforeRender 

See picture

 

post-224-0-72240500-1363357926_thumb.png

 

Regards

Link to comment
Share on other sites

Thank you patmap , شكرا

 

it's work , but i have another problem,

 

I used the "onbeforeunload function" to confirm Exit,

 

 

 
window.onbeforeunload = function{
 retrun "Are you sure you want to leave My system? The system will Terminate!";
}
 

 where i can put the code

   ajaxRequest(sender, 'SessionClosed', [] );

 

Thank you
 

Link to comment
Share on other sites

Thank you patmap , شكرا

 

it's work , but i have another problem,

 

I used the "onbeforeunload function" to confirm Exit,

 

 

 
window.onbeforeunload = function{
 retrun "Are you sure you want to leave My system? The system will Terminate!";
}
 

 where i can put the code

   ajaxRequest(sender, 'SessionClosed', [] );

 

Thank you

 

 

Hi,

 

Browsers act different in this case and you cant hope to do in all browser

you can add this code Instead of the previous code:

 

  window.onunload = function() {
      ajaxRequest(sender, 'SessionClosed', [] );
  };
  
  window.onbeforeunload = function() {          
     return "Click Leave this page to Session Closed.";
  };

 

 

But this code run on FF and dont run on Google chrome.

 

There are not %100 safe solution for confirming !

 

Regards

Link to comment
Share on other sites

IMHO, it is better to place this code in MainForm.Script. It works in both cases (mfPage, mfWindow)

for example:

function bunload(){
dontleave="Are you sure? The program will be closed!";
return dontleave;
};
function ounload(){
ajaxRequest(MainForm.window, 'SessionClosed', [] );
};

onbeforeunload = bunload;
onunload=ounload;

 

 

for me, it works on FF, IE, Chrome. But Opera doesn't support both events (((. 

  • Upvote 2
Link to comment
Share on other sites

  • 9 months later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...