Clear session variable when the application is closed

Clear session variable when the application is closed

  

Hi,

I would like to clear the session variables when the application is closed. May i know where and how can i clear it?

Hi Jace,

How are you closing the application? From browser without logging out or with keyboard keys?

Hi,

My application does not require login. So the application will be closed when the user close the browser.

Hi Jace,

You can use below JS to clear session variable on Close of your application.

$(document).ready(function()
{
    $(window).bind("beforeunload", function() { 
            var elemid = $('.autobutton').attr('id');
            var elem = document.getElementById(elemid);             
            if (typeof elem.onclick == 'function')
            {                 
                elem.onclick.apply(elem);
            }
         
        //return confirm("Do you really want to close?"); 
    });
});

I am also here with attaching sample oml for your reference.

Sachin

Sachin Mahawar wrote:

Hi Jace,

You can use below JS to clear session variable on Close of your application.

$(document).ready(function()
{
    $(window).bind("beforeunload", function() { 
            var elemid = $('.autobutton').attr('id');
            var elem = document.getElementById(elemid);             
            if (typeof elem.onclick == 'function')
            {                 
                elem.onclick.apply(elem);
            }
         
        //return confirm("Do you really want to close?"); 
    });
});

I am also here with attaching sample oml for your reference.

Sachin

Hello,

Thanks for the oml. But when and where should i call the screen action. 

I want to clear all the session variables whenever user reopen the application.


Hi Jace,

you can follow a method to call server side logout page on unloading of your document area using jquery.

  $.post("logout.aspx?action=logout",{},function(data){
    location.href="logout.aspx";
});

you can call this inside your document unload function defined at page level.