+ 2

Go to 2 pages back and reload using javascript

I am making a website in which after submitting a form, i want to make user go 2.pages back with Javascript and reload the oage using javascript. How can i do that?

18th Jun 2020, 2:11 PM
Karan Rajput
Karan Rajput - avatar
10 Respostas
0
Karan Rajput you will have to send get parameters along with the url. You can maybe send the name of the page, or maybe the full URL. Something like this window.location = "/signup?came_from_page=products" And then from the signup page, you can get the parameters using window.location.search let get_params = window.location.search And after successfully signing up, you can send the user back to the page he/she came from by doing window.location = whatever_the_params_you_got Also, a side note. You said that Lily Mea 's answer works, but doesn't reload the page. You can reload the page by doing window.location.reload()
19th Jun 2020, 4:46 AM
XXX
XXX - avatar
+ 3
Lily Mea is correct. Whoever downvoted her, please undo your downvote, otherwise I'll log the downvoters offending "downvote abuse" https://developer.mozilla.org/en-US/docs/Web/API/History/go
18th Jun 2020, 3:56 PM
Gordon
Gordon - avatar
+ 2
Instead of making the browser go two pages back, you can just go to the url of the page like this window.location = url
18th Jun 2020, 2:28 PM
XXX
XXX - avatar
+ 1
try history.go(-2) idk if it works though
18th Jun 2020, 2:40 PM
durian
durian - avatar
0
But sometimes i want to send back user to home page, sometimes to category page, and sometimes to product page. So do you have an solution for this?
18th Jun 2020, 2:32 PM
Karan Rajput
Karan Rajput - avatar
0
Karan Rajput I'm not sure how to achieve what you are asking for. But I'll just like to add that when you use window.location, you can navigate through the pages of the current website. For example, if you are on the url "www.website.com/user", you can go to "www.website.com/products" just be doing window.location = "/products" So while making your website, you will have certain patterns, for example "www.website.com/category" for category page, "www.website.com/home" for home page. With window.location you can easily navigate through them
18th Jun 2020, 2:48 PM
XXX
XXX - avatar
0
Lily Mea it works but doesn't reloads the page
18th Jun 2020, 6:06 PM
Karan Rajput
Karan Rajput - avatar
0
XXX but then how will i know that from which page user has come to sign in. Imagine youre shopping at amazon, you were finding a product and after 10-15 minutes you found the product you was looking for. But you'll have to register before buying so you registered and then amazon redirected you to home page. Your time got wasted and maybe you'll not buy anything because of this. Im too making an shopping site.
18th Jun 2020, 6:10 PM
Karan Rajput
Karan Rajput - avatar
0
XXX ok sir thank you very much. Window.location.reload() can reload current page only
19th Jun 2020, 4:45 PM
Karan Rajput
Karan Rajput - avatar
0
Karan Rajput yes window.location.reload() reloads the current page only. You can first go back 2 pages and then reload the page.
19th Jun 2020, 4:52 PM
XXX
XXX - avatar