Ahsan Attari
Ahsan Attari

Reputation: 659

Clear browser history in jquery or javascript so that the user can not click the back button?

I have scenario where the user clicks "log off" and is redirected to the home page. However when he redirects to the homepage if he clicks the back button of the browser he can return to the working area. I need to prevent him from coming back to the working area after he logs off. Can anyone help ?

Upvotes: 3

Views: 7296

Answers (2)

user1638126
user1638126

Reputation: 79

Make a session variable as 0 upon logout and check for its value in a script tag on the top of the page. If it is 0 stay on the login page. This will prevent back button from entering inside the login page.

Upvotes: 0

Gaurav Gupta
Gaurav Gupta

Reputation: 5416

There's nothing you can do to prevent a user from revisiting a previously visited URL, even after they have logged out. Your session-management code needs to manage this situation. If the user no longer holds a valid session, the request should not execute.

If you're trying to prevent the browser from displaying a cached version of a post-login page after a user has logged out, you can set an HTTP Cache-Control header with a value of no-cache on pages accessible after login.

Upvotes: 1

Related Questions