【发布时间】:2018-02-16 10:41:33
【问题描述】:
如何使用 javascript 显示上一个窗口。我有两个 html 页面,例如 test1.html 和 test2.html
test1.html
<button id="newWindow">New Window</button>
test2.html
<button id="prevPage">ok</button>
如果我从 test1.html 中单击 newWindow 按钮,它将转到新选项卡窗口中的 test2.html。
如果我从 test2.html 页面单击 prevPage 按钮,它将关闭当前窗口选项卡并应该转到 test1.html 选项卡窗口。
$(document).on('click', '#newWindow', function () {
window.open("test2.html");
});
$(document).on('click', '#prevPage', function () {
/*close pressent window(test2.html)*/
window.close();
/*open the test1.html tab window*/
window.opener('test1.html','parent').focus();
});
【问题讨论】:
-
您可以尝试将上一页保存在本地存储中并访问它,据我所知历史 API 不提供以前状态的信息。
-
嗯,如果你使用普通的超链接而不是
window.open(),prev url 不会显示在历史 API 中吗? -
过去有一个功能可以将当前和以前的字符串显示为只读字符串,developer.mozilla.org/en-US/docs/Web/API/History 但在某些情况下已经过时,我在 api 中没有看到任何标准解决方案案例...
-
您可以使用 window.location.href 看到当前,但您看到我无法知道过去的字符串...按照 OP 的要求
标签: javascript jquery