Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log out from browser if the browser closes in asp .net?

my requirement is bit of complicated . an user is accessing the data base using the web browser, while accessing the data base if the user is closed the active page instead of log out the session - that session needs to be log out automatically. can some one guide me how to make this ? i am used jquery - in the master page.

onbeforeunload - i am getting message leave the page or stay with this page. even i am getting this messages while login and and view the home page too.

like image 677
prabhakaran S Avatar asked Oct 19 '12 18:10

prabhakaran S


People also ask

How do I close a user session when browser is closed?

we can find the tab/browser close event in javascript using " window. onbeforeunload " & " window. onunload " events. you just need to call the logout action from javascript by clicking on logout icon.


1 Answers

This is the sample code

  window.onbeforeunload = function () {
   return 'You want to leave?';
};​​

see demo here

I think its possible to send an ajax request and you can saw your server that the user closed the browser's tab.

Also this a jquery plugin called jquery.idle, which is used to identify if the user is active.

Refer this Detecting idle time in JavaScript elegantly will gives you more idea.

like image 155
kbvishnu Avatar answered Oct 23 '22 15:10

kbvishnu