Find your content:

Search form

You are here

Logout a user automatically when the browser window is closed


I have a basic question about Salesforce session: How can I logout my users automatically when they close the browser window?

Attribution to: toufik_at

Possible Suggestion/Solution #1

I see this is an old thread but I thought I would share a workaround I discovered ...

Add a controller to your site home page, and in the init action, redirect to secure page, if it is not already a secure page.

public PageReference init() {
        String currentURL = Site.getCurrentSiteUrl();
        if (!startsWith(currentUrl, 'https://')) {
            return redirect(currentURL.replace('http://', 'https://'));

        return null;

Link to the thread HERE

Attribution to: Curt

Possible Suggestion/Solution #2

I think if we talk about custom pages then by using JS this may be possible (that also need POC), but other than that it is quite impossible to do this with all native pages (home page component can help?).

Attribution to: Forceguru

Possible Suggestion/Solution #3

Well, to log a user out you redirect them to /secur/logout.jsp ... however enforcing that mechanism would either have to be done via JavaScript or in theory you could also use a Browser Extension

Attribution to: joshbirk
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content