Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove a page from the browser history?

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.

like image 910
Rory Becker Avatar asked Nov 14 '08 13:11

Rory Becker


5 Answers

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.

like image 83
Eugene Yokota Avatar answered Oct 04 '22 19:10

Eugene Yokota


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.

like image 27
splattne Avatar answered Oct 04 '22 21:10

splattne


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.

like image 29
dub Avatar answered Oct 04 '22 19:10

dub


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.

like image 22
Patrick McElhaney Avatar answered Oct 04 '22 19:10

Patrick McElhaney


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

like image 29
Rich Avatar answered Oct 04 '22 19:10

Rich