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()
{
var width;
var height;
var BrowserName = navigator.appName;
if (BrowserName == "Microsoft Internet Explorer") {
height = document.documentElement.clientHeight;
width = document.body.clientWidth;
}
else
{
height = window.innerHeight;
width = window.innerWidth;
}
var win = window.open("about:blank", "_self");
win.close();
var newWin = window.open('Login.aspx');
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.