Click here to Skip to main content
Click here to Skip to main content

Tagged as

Browser Back Button handling after Sign Out through JavaScript

, 5 Nov 2013
Rate this:
Please Sign up or sign in to vote.
This simple Tip/Trick is focused on providing a simple and cross browser compatible solutio.

Introduction

Disabling/Handling Browser's back button is a common functionality to be implemented or the problem to be solved during development of web applications now a days.  So when I found this problem in front of my nose, it took my a lot of time to understand and implement it as per my project. This simple Tip/Trick is focused on providing a simple and cross browser compatible solution in this context.

Using the code 

JavaScript has become a most commonly used platform to sort out different types of problems on the client side (some time to enhance functionality and some time due to client restriction). In the same way, I have chosen the JavaScript to solve this oldie goldy problem.

To make my work (code) compatible for major browsers, I have extended the script a bit, So that it could work without any error.

I have created a JavaScript function in ASPX page which is being called from the code behind of  SignOut page of my application after the handling of Sessions (i.e., abandoning/clearing the sessions etc.).  

function ClearHistory()  
{ 
    //defining variables to get the browser width and height.
    var width;
    var height;

    // getting the Browser name which is currently in use.
    var BrowserName = navigator.appName;

    //handling the IE due to limitations of this browser
    // i.e., failure in getting proper height of browser.
    if (BrowserName == "Microsoft Internet Explorer") {
        //setting up height and width variable values.
        height = document.documentElement.clientHeight;
        width = document.body.clientWidth;
    }
    // code block to be executed in case of other browsers.i.e. except IE.
    else
    {
        height = window.innerHeight;
        width = window.innerWidth;
    }

    // getting the currently opened window. and than closing it to get rid of back button.
    //Mainly this is done to cover up the firefox limitation of window.close()
    var win = window.open("about:blank", "_self");
    win.close();

    //Opening a new Window with the Login page url
    //to redirect the user towards successful signout.
    var newWin = window.open('Login.aspx');

    //formatting the newly opened window to be adjusted accordingly.
    newWin.focus();
    newWin.moveTo(0, 0);
    newWin.resizeTo(width, height);
}

Points of Interest

While searching for a solution for this problem, I found a lot of solutions posted around, and I have created this by combining parts from there. 

I hope this could be much helpful and easy to implement (even though there is some hotchpotch). Any guidance from the seniors, comments/suggestions/errors are truly welcomed. 

License

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

Share

About the Author

VICK
Software Developer
Pakistan Pakistan
Have Masters Degree in Information Technology (MIT).
Working as .NET Developer in a US Based software house.
Started my "As Developer" Professional career just a year ago.
Wanted to be an All Round developer and dreamed to be working for some Giant Tech ICONS one day.
 
Visit My Blog!
 
Contact Me!

Comments and Discussions

 
SuggestionTypo in title Pinmvpthatraja5-Nov-13 22:37 
GeneralRe: Typo in title Pinmember VICK5-Nov-13 23:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140902.1 | Last Updated 6 Nov 2013
Article Copyright 2013 by VICK
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid