如何恢复背面页面(历史记录)? [英] How to restore page on back (history)?

查看:105
本文介绍了如何恢复背面页面(历史记录)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含静态元素的页面,但有些页面是在load事件上动态添加的-假设我填充了要选择的语言列表.当用户选择语言后,进入下一页,然后返回上一页,将再次构建语言列表,并选择列表中的第一项,而不是先前选择的一个用户.

I have a page with static elements, but some are added dynamically on load event — let's say I populate the list of languages to pick. When the user select the language, and proceeds to the next page, and then gets back to the previous one, the list of languages will be built again, and the first item on the list will be selected, not the one user selected previously.

所以我的问题是-如何(如果可能的话)恢复页面的先前状态?

So my question is -- how (if it is possible) restore the previous state of the page?

推荐答案

您有三个选择.

1)将用户选择存储在本地存储中,并在页面加载时从本地存储中读取并相应地填充页面.

1) Store the users selection in local storage and when the page loads read from local storage and populate your page accordingly.

2)当用户进行更改时,请将这些更改发布到Web服务器,并将数据保存在会话对象或数据库中.然后,当您再次加载该页面时,请进行ajax调用,以从服务器中获取所需的数据.

2) When the user makes changes POST those changes to a web server and save the data in a session object or DB. Then when you first load the page again make an ajax call to GET the needed data from your server.

3)将页面写为单页应用程序,而不是导航到新页面,而是修改已有的页面(例如,隐藏一个div并显示另一个div),以免丢失数据.

3) Write your page as a single page application and instead of navigating to a new page modify the page you have (e.g. hide one div and show another) such that you don't lose you data.

这篇关于如何恢复背面页面(历史记录)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆