8

Possible Duplicate:
Prevent Use of the Back Button (in IE)
Disabling Back button on the browser
How to disable Back button in IE and firefox?

Penalty of times, i did not think it appropriate to post this question because it has been already asked lot of times, but this time I am posting being ready for consequences, because I have no other option. I will answer any comments, I can also show my try(in which you would be interested) at any link given below.

I have a loginpage and a page1. I need to handle or not work browser back button on loginpage. It is possible as I have done it for FF and Chrome but unable to do for IE. My working code for FF is following.

window.onload = function ()
{
    if (typeof history.pushState === "function")
    {
        history.pushState("jibberish", null, null);
        window.onpopstate = function ()
        {
            history.pushState('newjibberish', null, null);
            // alert('back button pressed');
            // This works in Chrome and FireFox but not in IE
        };
    }
}

I need to have some code (working on all browsers) in my loginpage so that : Desired Output : pressing back button on login page would not take user back to page1 (just like facebook login page). I do not want to disable back button, just to handle its click on loginpage.

Edit From Comments. Please give answer what to do, i have read "Not to do this" but not what to do. Following Code works on pageload ever time except when this page (page1) is loaded through a back button click on loginpage

  if (Session["role"] == null)
        Response.Redirect("login.aspx");

I have tried to follow a few questions on same issue, but have been unable to get what I need. I will prefer not using window.location.hash just but ready if there is no other solution

Code Project - Browser back button issue after logout

BlogSpot - Detect back Button of Browser

SO - Disable browser back Button

SO - Disabling Back button on the browser

SO - Detect Back Button Click

SO - On window.location.hash - change?

Following are few plugins. I tried to follow, but don't know if they are made for what I need and if they are I have been unable to use any of them correctly

Salajax: simple Ajax library

A better AJAX Back Button Solution

history.js

Community
  • 1
  • 1
Sami
  • 8,168
  • 9
  • 66
  • 99
  • @Bergi I've seen that one, just pasted the wrong tab link. Cannot undo :) anyway. – Roko C. Buljan Nov 23 '12 at 12:28
  • Yes @Bergi unfortunately I missed/could not find [Prevent Use of the Back Button (in IE)](http://stackoverflow.com/questions/54539/prevent-use-of-the-back-button-in-ie). I am reading it – Sami Nov 23 '12 at 12:31
  • @Sami: It just states the same as all the others: It's not possible (in a clean way), and there is no good reason to do so. – Bergi Nov 23 '12 at 12:33
  • @Bergi Right. Please post as answer or give a link where it is told that what to do then. I have read not to do but not what to do.. Please also tell **how and why facebook does this?** For me it has not been possible only in IE **I have done in FF and Chrome** – Sami Nov 23 '12 at 12:37
  • @Sami: What is your reason to want to prevent the back button? I don't know what Facebook exactly does. – Bergi Nov 23 '12 at 12:40
  • @Bergi I want user could not be able to view pag1's data without being authenticated. And there is no way for user to go to page1 without authentication except pressing back button on loginpage – Sami Nov 23 '12 at 12:42
  • @Sami: What would happen if the user manually navigates to pag1 without authentification? – Bergi Nov 23 '12 at 12:44
  • @Bergi Pageload of page1 checks if the user has permissions but it does not work only when navigating to page1 through back button click on loginpage – Sami Nov 23 '12 at 12:45
  • @Sami: How do you check that? Why does that check not work when navigating through the history? Show us some code. – Bergi Nov 23 '12 at 12:48
  • @Bergi. See my edit please I am using `if (Session["role"] == null) Response.Redirect("login.aspx");` on page1, which only does not work when coming on this page1 by clicking back button on loginpage – Sami Nov 23 '12 at 12:55

0 Answers0