Jake 404
Jake 404

Reputation: 171

JavaScript going back multiple times in history

I know to go back in history with JavaScript you use:

window.history.back();

But how can I go back multiple times.

e.g. to go back 4 times I tried:

window.history.back().back().back().back();

But it didn't work. How can I go back multiple times in history with JavaScript.

Upvotes: 1

Views: 2631

Answers (3)

Peko
Peko

Reputation: 126

You can also do:

window.history.back(4)

Upvotes: 1

merlot
merlot

Reputation: 194

i = number of pages you want to go back

window.history.go(-i) 

Upvotes: 6

kol
kol

Reputation: 28688

Use history.go(-4). Source: MDN

Upvotes: 1

Related Questions