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?
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?
Share Improve this question edited Aug 29, 2013 at 19:29 Diosney 10.6k15 gold badges68 silver badges113 bronze badges asked Aug 29, 2013 at 18:46 Pedro CruzPedro Cruz 831 gold badge1 silver badge4 bronze badges 3- You need to refresh the page. Have a look at this tinyurl.com/Jez-D007 – Jez D Commented Aug 29, 2013 at 18:53
- How about window.location.href = "your_desired_url"; instead of window.history.back(); – srijan Commented Aug 29, 2013 at 18:59
- Because there are two different pages that link to the one in question, and I can't know which one called it. – Pedro Cruz Commented Aug 29, 2013 at 19:02
1 Answer
Reset to default 21You 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);