繁体   English   中英

如何使用javascript显示打开的标签窗口

[英]How to show opened tab window using javascript

如何使用 javascript 显示前一个窗口。 我有两个 html 页面,如 test1.html 和 test2.html

测试1.html

 <button id="newWindow">New Window</button>

测试2.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();

     });

我很确定你需要让第一个窗口仍然打开才能打开一个新窗口,否则 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();
});

为什么不依赖历史对象和简单的写入

window.history.back();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM