[英]How to show opened tab window using javascript
How to show previous window using javascript.如何使用 javascript 显示前一个窗口。 i have two html page like test1.html and test2.html
我有两个 html 页面,如 test1.html 和 test2.html
test1.html测试1.html
<button id="newWindow">New Window</button>
test2.html测试2.html
<button id="prevPage">ok</button>
If i click newWindow button from test1.html it will go to test2.html in new tab window.如果我单击 test1.html 中的 newWindow 按钮,它将转到新选项卡窗口中的 test2.html。
If i clcik prevPage button from test2.html page it will close current window tab and should go to the test1.html tab window.如果我从 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();
});
I'm pretty sure you need to have the first window still open in order to open a new one, otherwise the js function process is lost before that happens.我很确定你需要让第一个窗口仍然打开才能打开一个新窗口,否则 js 函数进程会在这之前丢失。 So you should open your new window first, then close the original one.
所以你应该先打开你的新窗口,然后关闭原来的窗口。 Like this:
像这样:
$(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();
});
为什么不依赖历史对象和简单的写入
window.history.back();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.