javascript - History back() Method go back twice - Stack Overflow

Using this sample code as an example:Go Back<script>function goBack() {window.history.back();}

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.

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.

Share Improve this question asked Jul 6, 2017 at 12:37 aderryaderry 1571 gold badge3 silver badges11 bronze badges 2
  • 2 Actually window.history.go(-2); should work, can you publish a snippet? – Iaconis Simone Commented Jul 6, 2017 at 12:41
  • 1 Wow, it is working as expected now. I swear it wasn't working as expected a few moments ago. thank you though. – aderry Commented Jul 6, 2017 at 12:47
Add a ment  | 

2 Answers 2

Reset to default 7

Now

window.history.go(-2);

works; strange.

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743734457a4497999.html

相关推荐

  • javascript - History back() Method go back twice - Stack Overflow

    Using this sample code as an example:Go Back<script>function goBack() {window.history.back();}

    6天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信