Reputation:
I am making a simple web app that opens a url on entering a query. I am using the bottle framework in Python. The problem I am facing is as follows:
I have two URL handlers, one for /
and other for /process
. When the user enters a query through a form on /
, the form action goes to /process
which then processes the query and opens a particular url using window.open(url, "_self")
. Now when the user hits the back button in the browser, /process
is called again with the same query, which then again loads the same url. Instead of this, I want it to go /
when the back button is pressed. How can I do this? Thanks.
EDIT : I did not notice this before but the above undesired behavior is found in Firefox but not in Chrome.
Upvotes: 1
Views: 1354
Reputation: 943591
Don't redirect using window.open
, or any kind of client-side JavaScript.
Have the HTTP response to the request for /process
be a 302 Found
HTTP status with a Location
header.
See also The Post/Redirect/Get Pattern.
Upvotes: 0
Reputation: 7108
You can use the window.history object to manipulate and replace the history or, instead of using window.open(url, "_self")
, replace the location
example:
window.location.replace(url);
Check some documentation and this answer In Javascript, how do I "clear" the back (history -1)?
Another solution could be to intercept when the user is going to go back. Check this answer to have some examples:
Intercepting call to the back button in my AJAX application: I don't want it to do anything!
Upvotes: 1