0

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 ?

4

3 回答 3

1

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.

于 2013-03-30T08:17:25.810 回答
1

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”);

于 2013-03-31T06:30:20.057 回答
0

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
});
于 2013-03-31T06:46:03.113 回答