When a user clicks on the logout button, I have a JavaScript function that collects the user session that was stored It works fine on Mongodiibi.
In addition to this, I want to clear the user session when the user closes the browser. The problem I am facing here is: When the user clicks on the Fresh Icon, call the logout function is being done. I only want this function when the browser closes.
Can I stop calling this function on page refresh?
My argument here is to clear the session. The browser is closed. I am removing the session which is on Mongodi. Is there a better way of managing session?
var isRefresh = false; $ (Window) .Kiddown (function (event) {if (event.keyCode == 116) {// press F5 to refresh user refresh = true;}}); // When you close the browser, when the logout function calls, then the session clears the data Var WindowsClivic Listener = Window.Attavent || Window.addEventListener; Var chkForBrowserCloseEvents = window.attachEvent? 'Onbeforeunload': 'beforeunload'; /// IE 7, IE 8 Compative WindowCliveEvent Listener (chkForBrowserCloseEvents, Function (e) for {//> = IE 7, Chrome, Firefox if (! Refresh) {$ scope.logout ();}}) ;
So far I know that you do not really test to close the browser Can ; You can test to close only one window (or tab), this is usually enough, unless there is no page-refreshing, because it will close and reopen a web page inside a window or tab. What is needed to click on the browser's page-refresh button is counted as an event handler, but I'm not sure that it exists. Here's something:
One thing that is fresh in my attempt to know something about the page -Handler is the concept of using "local storage" as part of a pre-unload handler, you can stamp a small data item in local storage. Activate a type of timer on the server, and wait for that time to expire before the session is deleted. When your page loads, test the local storage for that data item. If it exists and the time-stamp was very recent, then you know that the page was refreshed and can do the right thing on the basis of knowing that it does not erase the session by sending an AJAX message to the server Saying to do.
Comments
Post a Comment