简体   繁体   中英

javascript to go back pages

Currently I am using the code below. This works at the moment, but say the users leave information that needs to be filled in and clicks confirm as it redirects to the same page and shows the error. but if they were to press the cancel button at this point then the users goes back to the previous form which he filled out, if he then presses cancel on that page goes back to the initial page, how would I use this method to select the first page that it had and not the previous?

javascript:history.back()

You can use the go() method to go back twice, or manipulate the browser history in a way that any error showing page will not create a history entry. You have to count how many pages you want to ignore an call

window.history.go(-3); 

See here: https://developer.mozilla.org/en-US/docs/DOM/Manipulating_the_browser_history

I don't have any code handy, but I find it best to store the initial location either in a hidden field or a cookie, then use DJ KRAZE's suggestion. That way you have complete control over where you intend to go upon an error or cancel or whatever.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM