开发者

How to alter browser's back button functionality similar to eCommerce sites in asp.net

开发者 https://www.devze.com 2023-02-17 22:03 出处:网络
I have a web application, in which browser\'s back button functionality should be customized. It\'s like, whenever we click on browser\'s back button, it should take us to landing page(Login page), It

I have a web application, in which browser's back button functionality should be customized. It's like, whenever we click on browser's back button, it should take us to landing page(Login page), It should display error message saying that 'session expired. Please login again'.

I have gone through so many posts and even in stack overflow also, i saw few posts. But nothing worked for me. The java script approach i am using as a temporary workaround.Basically this JavaScript never allow us to go back. instead it will keep us in same page. JavaScript i have used <script>history.go(1)</scr开发者_运维技巧ipt>

Please help me to customize the functionality of Browser's back button. Any suggestions will be really helpful to me.


Short answer: You cannot
A little longer: You shouldn't even try.

But if you insist: A Thorough Examination of "Disabling the Back Button." (from 2000, but since it is ASP I guess still valid for you :)

Newer dot net: Restrict user go back to previous page after signout

Ignore the older browsers do not support location.replace - IE3.2 is not considered older any more but ancient.


For this - you would need a custom solution and disabling back button will not help...

Usually you should not try to change the behavior of back button. But since this is the requirement, I would suggest the following:

Approach 1:

This calls for creating a navigation framework where you know which is the current page in the flow... This is only possible if you a sequence in which the pages will be called (like a wizard)

Approach 2:

Specific to your case : You can use jquery/javascript to identify if the back button is clicked.. If it is then you can do an ajax call to server to kill the session and then redirect the user to login page.


You can programmatically manipulate browser history using something like this: window.history.back(); window.history.forward(); window.history.go(2); etc.

In HTML5 ready modern browsers like Chrome you can also do more advanced things including completely overwriting back button functionality using history.pushState() and history.replaceState() methods. (https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history)

You can also go dirty and use javascript + ajax calls to react specifically to back button events, but this will also not work on some browsers. What you ask is not a native part of a web, so no matter what you will decide to use in the end, it wont be very easy or widely supported.

0

精彩评论

暂无评论...
验证码 换一张
取 消