Reputation: 3189
Currently I have 2 pages based on the following URL MyNewApp/purchase
and MyNewApp/confirm
. On the 2nd page that is /confirm I added a back button with the following
HTML
<button type="submit" class="btn" id="back">
Go Back
</button>
JS
$('button[id="back"]').click(function() {
this.form.action="backToPurchase";
this.form.method="GET";
});
After pressing the back button everything works fine except the URL changed to /MyNewApp/backToPurchase?_method=
. How can I set the URL to /MyNewApp/purchase
after pressing the back button ?
Upvotes: 0
Views: 2166
Reputation: 3441
I would recommend a better option, instead of submitting a form just for redirection, use the following:
$('#back').click(function() {// <-- selecting by id is much faster than selecting by attribute "id"
location.href = '/backToPurchase'; // or '/purchase';
// OR you can do the following :
history.back(); //this will performs as you clicked the back btn from the browser
});
Upvotes: 0
Reputation: 48256
This is technically the answer to your question, though you might want to think about a better way to do what you want.
window.history.pushState(null, null, “/new-url”);
Upvotes: 1
Reputation: 1423
You Can't just change the URL as you wish. Think about it, if you could change the URL like that it would be a big security problem.
BUT try to use POST instead, or just send the user to a new page so the URL will change, You have lots of options to solve it, just think.
Upvotes: 1