High5
High5

Reputation: 51

How to use history.back()

can i do the following?

window.open(“any url”, “_self”)
history.back()

I want to go to the other page and then return to previous one, but this aproach doesn't work. Is this impossible, and history.back() can't be used this way, because the scripts on the new page get loaded instead of the old one? Also, i tried to do the window.open on one page and do history back from the other, it still doesn't work...

Upvotes: 3

Views: 408

Answers (3)

High5
High5

Reputation: 51

The problem was that the browser did the relocation faster than it stored the previous page in history. When I wrapped window.open() (the first page) and history.back() (the other page) with functions and called them with the button's onclick attribute it worked. '
Thanks everyone.

Upvotes: 0

Peko
Peko

Reputation: 126

Once the page is reload, the code below won't get executed.

Upvotes: 1

Arvind Sharma
Arvind Sharma

Reputation: 77

You may like to use history.go(-1) This will be more effective and generic, and will give you added advantage to go back further than the previous page. thanks

Upvotes: 1

Related Questions