如何使用javascript显示打开的选项卡窗口
如何使用javascript显示上一个窗口。我有两个html页面,比如test1.html和test2.html test1.html如何使用javascript显示打开的选项卡窗口,javascript,jquery,Javascript,Jquery,如何使用javascript显示上一个窗口。我有两个html页面,比如test1.html和test2.html test1.html <button id="newWindow">New Window</button> 为什么不依赖历史对象和simpywrite呢 window.history.back(); 我非常确定,您需要让第一个窗口仍然打开才能打开一个新窗口,否则js函数进程将在这之前丢失。因此,您应该先打开新窗口,然后关闭原来的窗口。像这样: $(doc
<button id="newWindow">New Window</button>
为什么不依赖历史对象和simpywrite呢
window.history.back();
我非常确定,您需要让第一个窗口仍然打开才能打开一个新窗口,否则js函数进程将在这之前丢失。因此,您应该先打开新窗口,然后关闭原来的窗口。像这样:
$(document).on('click', '#newWindow', function () {
/*open test2.html*/
window.open('test2.html').focus();
/*close test1.html*/
window.close();
});
$(document).on('click', '#prevPage', function () {
/*open test1.html*/
window.open('test1.html').focus();
/*close test2.html*/
window.close();
});
您可以尝试将上一页保存在localstorage中并访问它,据我所知,history API不提供上一状态的信息。嗯,如果您使用普通的超链接而不是
window.open()
,以前的url不会显示在历史API中吗?过去有一种功能可以将当前和以前的url显示为只读字符串,但在某些情况下,这种功能已经过时,并且我在API中没有看到任何针对这种情况的标准解决方案…您可以通过window.location.href查看当前url,但您可以看到我无法知道过去的字符串。。。按照OPThan的要求,您必须首先打开上一个窗口,然后关闭当前窗口。但有一个问题……你是否完全有必要在一个单独的窗口中打开这个新页面。您可以在同一窗口中打开,然后“上一步”按钮将处理历史记录。这在chrome中不起作用:self.close();var mypreWindow=window.open('test1.html','Start Page');mypreWindow.focus();美元(“#转账资金”)。对话框(“打开”);在窗口中不需要第二个参数。打开函数。
window.history.back();
$(document).on('click', '#newWindow', function () {
/*open test2.html*/
window.open('test2.html').focus();
/*close test1.html*/
window.close();
});
$(document).on('click', '#prevPage', function () {
/*open test1.html*/
window.open('test1.html').focus();
/*close test2.html*/
window.close();
});