code to detect browser back button click for any(all) browser [duplicate]

时间秒杀一切 提交于 2019-12-10 03:12:31

问题


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

来源:https://stackoverflow.com/questions/13529025/code-to-detect-browser-back-button-click-for-anyall-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!