Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reload previous page with javascript?

I have a website in ASP VB.NET and there's a page that goes back to the previous one when clicked, we did this with JavaScript:

window.history.back();

But this gets you to the previous page on the state it had when going to the current page, we need it to reload, how can you do this?

like image 790
Pedro Cruz Avatar asked Aug 29 '13 18:08

Pedro Cruz


1 Answers

You can't use window.history to achieve your desired behaviour because this is not how it works. window.history preserves the session history of the pages visited (as stated here - it essentially mimics your browsers back/forward buttons.

As stated in the document:

There is no way to clear the session history or to disable the back/forward navigation from unprivileged code. The closest available solution is the location.replace() method, which replaces the current item of the session history with the provided URL.

So your best bet to make this work would be to use location.replace(). You can get the previous URL of where you came from using document.referrer.

location.replace(document.referrer);
like image 155
Suvi Vignarajah Avatar answered Sep 22 '22 05:09

Suvi Vignarajah