History.go (-1) does not work on chrome. Any alternative?

In my project I use below Javascript code history.back (); to return to the previous page (for example, the back arrow on the window). This feature works fine on IE and Firefox, but not on google crome?

<input type="button" value="Go back" onclick="history.go(-1); return false" /> 

I will get the error below

Form Resubmit Confirmation

This web page requires data that you entered earlier in order to be displayed correctly. You can send this data again, but by doing so you will repeat any action that this page previously performed. Click Refresh to resubmit this data and display this page.

Was there a googling, but everyone suggested history.go (-1); return false; but it doesn’t work either. Also tried history.back (), but that doesn't help either

+6
source share
3 answers

The previous page was displayed after the POST request (this usually happens when the form is submitted). This means that in order to display the previous page, the form data that was sent to the POST request must be submitted again. This has nothing to do with your history.go(-1) Javascript, it will also happen when you click the back button of your browser.

You can use Post Redirect Get to get around this problem.

You can also use GET in your form:

 <form action="..." method="GET"> 

However, do not use this for forms where data is added to your server, or they will be sent each time the user accesses the button and returns to this page. See Also: When should I use the GET or POST method?

+6
source

Try the following:

 <script> function goback() { history.go(-1); } </script> <a href="javascript:goback()">Back</a> 

It works in Chrome and other browsers.

Above was copied verbatim:

http://simonthegeek.com/technical/history-back-problems-with-chrome-and-safari/

0
source

I would prefer client code instead of excusing my server
I tried this and it worked on all browsers:

 <button onclick="javascript:window.history.back()">Back</button> 

EDIT
Alternatively, you can use the web cache for storage, which was your last page, and then you can easily redirect to that page.

-1
source

Source: https://habr.com/ru/post/947714/


All Articles