Link to home
Start Free TrialLog in
Avatar of Soluga
Soluga

asked on

Log off a user when they leave web site

Hi,

I would like to log off a user if they leave my site.

I have tried a few things such as ....

        window.onbeforeunload = function(){
             $.ajax({
                type: "POST",
                //page and method
                url: "../KeepSessionAlive.aspx/logOutUser",
                async: false,
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                    error: function (xhr, ajaxOptions, thrownError) {
                    alert(xhr.status);
                    alert(thrownError);
                }
            });
         };

However this logs off the user if they leave the web page for another web page. I only want to invoke a log off if they actually navigate to another site altogether.

Would be grateful for any help.

Thanks
Avatar of Gary
Gary
Flag of Ireland image

There is no reliable way to detect it.
And even when it does work your alerts would not fire. There is only one option for the alert and that is 'Do you want to leave this website' - Yes/No (and the yes/no part you cannot change - or is it OK/Cancel - cannot remember)
Not going to happen. The browser does not know it is leaving the site until it has already left.  

Why is it you think you ned to know when they leave the site?

Cd&
Avatar of Soluga
Soluga

ASKER

Because if they leave the site and do not log off the web site then another user could potentially access the system by going back in history.
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial