简体   繁体   中英

Return a user to last page visited on browser close/crash?

I have a page where a user is filling out a very large multi-page form. I'm using garlic.js to persist data into localstorage on the event of a crash or misclick of closing the browser.

What's the easiest way I can go about getting the user back to the last page they were filling out after logging back in, in the event of a crash or browser closing?

Can I use localStorage for this or cookies? Fairly new to javascript so the simplest solution would be appreciated!

In case your page does not have any pre-requisites, you can follow below steps:

  1. On the page load, store the URL into the localStorage
  2. As soon as any input field is changed, store its value in localStorage

Now the browser crash accidentally and you reopen your application. From the localStorage -

  1. Fetch the last page URL and load it into browser
  2. As the page loaded, assign all inputs their previous values from LocalStorage.

What you could do:

Keep saving the data in localStorage every input

If for whatever reason the user browser crash and the client is disconnected, when he comes back, let him log back in, and let him access a new form.

On a new form, check if previous data exists, if so fill the inputs, if not it means that it's his first time.

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