简体   繁体   中英

How Can I Store User's Page History Using localStorage?

What I am trying to do is make an application that once the user has logged in, a session is started. The user then clicks on a 'Record Journey' button and then the user browses the web. Once they return to my page it will display the pages that they have just visited.

Would using html5 local-storage be the best option when trying to store the user's page history? And does it even allow me to do this? If not, what alternatives are available?

Thank you in advance.

There's no sane way to read the user's history using JavaScript in a web page.

If your "application" is a browser extension, then this is possible, using one of the APIs as exposed by the environment (eg chrome.history ).

When the "application" is used to track history on web pages you own, then that's possible. localStorage would indeed be a good choice, since the persistent data does not add overhead to web requests. Don't forget that the the storage size is limited .

I would recommend you to use locache - A JavaScript caching framework for client side caching in the browser using localStorage - gracefully degrades when the browser doesn't support localStorage.

https://github.com/d0ugal/locache

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