How do I remove a page from the browser history?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-01 01:55:11

问题


I have an have an ASP.Net page which contains a button. This Page contains a ServerSide Paypal button.

When pushed my server does various clever things on the back end and then rewrites the response as a form and some javascript which posts this form to paypal..

This all works great.

However, if the user then elects to click back, they will arrive at my generated self-posting form and that will forward them again to Paypal.

I thought if I could find a way to have my generated form page not exist in the history, then this will solve my problem. but I have no idea how to correct this.

How can I remove my page from the history or just have it never appear?

Update: Thanks to all... Those are some great answers. Upvoted all good ones but went with splattne on account of clever use of hidden field rather than cookies for basis of decision.


回答1:


I'm not sure if that can be done. But here is an idea how you could prevent that resubmit of the form.

You could insert a hidden input in your form which at the beginning would be empty. On submit you'll write a value in that field and make sure you check on every submit attempt if this field is empty.

If it is not empty on submit you know that the form was previously sent and you could warn the user.




回答2:


window.location.replace(URL);

window.location:

replace(url)

Replace the current document with the one at the provided URL. The difference from the assign() method is that after using replace() the current page will not be saved in session history, meaning the user won't be able to use the Back button to navigate to it.




回答3:


As a web application, you'll never have full control of the user's browser. Even if there was a way to instruct the browser to not store the page in history, which I doubt, you can't be sure it'll work. For example, a clever user could tweak an open-source browser to store every page in history, no matter what.

I think you should try to approach the problem from another angle. You could, for example, detect that it's the same form which is being forwarded and not send it to paypal the second time. The important thing is to do it server-side.




回答4:


Perhaps you could set a cookie before submitting the form.

When the page is loaded, check for the existence of that cookie (meaning the form was already submitted). If found, instead of automatically submitting the form, automatically go back (window.history.back()) again.




回答5:


I'm not sure if you can do this easily with PayPal integration, but the "Post / Redirect / Get" pattern can be used to address this problem




回答6:


A useful Hint for some might be this...

window.history.go(-2);

particularly in the advent of a load failure warning popup.




回答7:


You could simply programme your page not to submit, or to do something / navigate somewhere else, if window.referer is the Paypal page you are trying to avoid invoking a second time.



来源:https://stackoverflow.com/questions/290055/how-do-i-remove-a-page-from-the-browser-history

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!