简体   繁体   中英

How to catch an event when hitting the back button?

I'm wondering if there is any way to detect when a page is being reloaded after hitting the back button of a navigator, in ASP .NET?

Thanks

Unfortunatly as far as I know there is no fail safe way to do this, as it depends primarially on the browser. Some browsers will physically reload the content when you press back, others will cache it and just load a cache. Others will do a mix of both.

Client-side script can have some success in this, but the differences between browsers is considerable.

Conceptually, it makes little sense to do, as you would presumably then do something on the basis of this knowledge, which would change "history". Don't change history! :)

The most common class of problem I've found to make one want to do this is re-submission of a form, following a back. I would normally solve this by including a nonce in the form, and rejecting repeated nonces. UUIDs are handy in these cases.

Other cases have other solutions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM