aderry
aderry

Reputation: 157

History back() Method go back twice

Using this sample code as an example: Go Back

<script>
function goBack() {
    window.history.back();
}
</script>

Then, pressing this button will be the same as pressing the back button once on the browser.

However I would like to have a button that makes the back button pressed twice. I tried window.history.back(-2); but it doesnt work. also tried window.history.go(-2); but it doesnt give desired results. I could have the button link back to the page but the reason why i want it to go back instead is so that previously entered data in a form is preserved.

Upvotes: 7

Views: 12143

Answers (2)

Peko
Peko

Reputation: 126

window.history.back(2) and window.history.go(-2) could both work.

Upvotes: 1

aderry
aderry

Reputation: 157

Now

window.history.go(-2);

works; strange.

Upvotes: 7

Related Questions