History back() Method go back twice
Asked Answered
A

2

7

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.

Adolescent answered 6/7, 2017 at 12:37 Comment(2)
Actually window.history.go(-2); should work, can you publish a snippet?Neurophysiology
Wow, it is working as expected now. I swear it wasn't working as expected a few moments ago. thank you though.Adolescent
A
7

Now

window.history.go(-2);

works; strange.

Adolescent answered 6/7, 2017 at 12:48 Comment(0)
C
1

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

Curet answered 24/6 at 6:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.