从 href link 返回时如何恢复表单值?
How to restore form values when browsing back from href link?
我的应用程序中有一个搜索页面,当我在 <input>
字段中键入搜索词时,该页面会生成包含 links 到其他应用程序页面(仅限本地)的结果 - 通常的搜索行为。搜索页面上的锚点如下所示:
"<a href='#/learn' target='_parent'>Go to the Learn page</a>"
如果我单击 Go to the Learn page
link,它会按预期导航到 Learn
页面。点击浏览器后退按钮,返回 Search
页面,但输入字段和搜索结果为空。
我不想打开新的 window 或标签页。相反,将 window 内容替换为 linked 页面,然后返回到到达那里的结果,并尝试不同的 link.
如何恢复这些值?
谢谢,
鲍勃
使用:
localStorage.setItem('oldForm', [document.getElementById("input-id"), "..."]);
window.onload = function () {
var input1 = document.getElementById("input-id");
input1.value = localStorage.getItem("oldForm")[1];
//...
}
它应该有效
我的应用程序中有一个搜索页面,当我在 <input>
字段中键入搜索词时,该页面会生成包含 links 到其他应用程序页面(仅限本地)的结果 - 通常的搜索行为。搜索页面上的锚点如下所示:
"<a href='#/learn' target='_parent'>Go to the Learn page</a>"
如果我单击 Go to the Learn page
link,它会按预期导航到 Learn
页面。点击浏览器后退按钮,返回 Search
页面,但输入字段和搜索结果为空。
我不想打开新的 window 或标签页。相反,将 window 内容替换为 linked 页面,然后返回到到达那里的结果,并尝试不同的 link.
如何恢复这些值?
谢谢, 鲍勃
使用:
localStorage.setItem('oldForm', [document.getElementById("input-id"), "..."]);
window.onload = function () {
var input1 = document.getElementById("input-id");
input1.value = localStorage.getItem("oldForm")[1];
//...
}
它应该有效