I want to override back button in browser so that, for example, if a user came from A.aspx to B.aspx, when he tries to go back from B.aspx it should go to Home.aspx not A.aspx.
Is there any way to accomplish that? It doesn't matter if it's using ASP, C#, JavaScript or jQuery.
You could use JQuery to catch the browser back (popstate) event.
$(document).ready(function () {
if (window.history && window.history.pushState) {
window.history.pushState('forward', null, null);
$(window).on('popstate', function () {
window.location.href = 'http://stackoverflow.com';
});
}
});
Track the last page in the user's ASP.NET session. This can be done In C# by setting the "last page" on the session whenever an aspx page loads. When ASP.NET A.aspx loads, check the last page in the session before setting it. If it was B, redirect to home.
A guide to using session state in ASP.NET Web Forms: https://msdn.microsoft.com/en-us/library/ms178581.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With