Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Right now i am working on web application. Now my problem is i need to disable browser back button after login into application. right now if i clicked on back button of browser it is redirect to login page again. i need to disable back button. i am using below javascript code but it is working both chrome and firefox browser but not support IE Browser.
JavaScript
<script type = "text/javascript" >
          history.pushState(null, null, 'pagename');
          window.addEventListener('popstate', function (event) {
              history.pushState(null, null, 'pagename');
      });

     </script>

Could you please help me on the same.
Posted
Comments
F-ES Sitecore 10-Mar-15 6:11am    
People have been asking every day for over a decade how to disable the back button (google "asp disable back button") yet have you seen a single site that does it? It's not possible, design your site so that back\forward doesn't break it instead.

Do not...
The browser is the private property of the end-user. All you have is the inside box of the browser - called window...
Design your application in such way that back and forward buttons of the browser will not create a problem...
You maybe can check in your login page that you already logged in (some kind of state) and redirect to the referrer page...
Again do not mess with the browser, you are a guest there and you will be thrown away if you behave not nice...
 
Share this answer
 
Comments
[no name] 10-Mar-15 6:02am    
Oh, how I hate those sites messing with my back-button! +5
Kornfeld Eliyahu Peter 10-Mar-15 6:03am    
Fortunately it much harder in today browsers :-)
Thank you!
SanSkun 10-Mar-15 6:05am    
Hi Kornfeld Eliyahu Peter,

you have any source code for this
Kornfeld Eliyahu Peter 10-Mar-15 6:07am    
Not for you...And not because I'm greedy (I am!), but because there is no one-code for all size!
You have to fit a solution to your site...
I would suggest to check for Session on Login Page.

If Session exists, then redirect to Home or some Landing page according to your website's logic.
 
Share this answer
 
Comments
SanSkun 10-Mar-15 6:18am    
I have tried with redirecting to home page. The problem is that page load is happening every time and continuing upto infinite loop. So plz help me on this.
Check for IsPostBack property in Page Load, which will execute only for the first load. Like...

Page Load()
{
if(!IsPostBack)
{
// Logic to check session and redirect...
}
}
on the page , where your page redirected after login, put this javascript code simple on design page, I use this code and it always work for me.


function disableBackButton() {
window.history.forward();
}


Thanks
 
Share this answer
 
Comments
SanSkun 10-Mar-15 7:05am    
Not working this one .I have tried this.
deepankarbhatnagar 10-Mar-15 7:10am    
show your code please how you have implemented this code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900