简体   繁体   English

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

[英]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.

相关问题 如何使用 JavaScript 从新选项卡中关注打开的弹出窗口 window - How to focus on opened popup window from a new tab using JavaScript 在使用javascript打开的窗口中打开新标签页 - Open a new tab in the window opened using javascript 如何使用javascript访问打开的选项卡的数据 - How to access data of the opened tab using javascript 检查是否可以在 javascript 中打开新选项卡或 window - Checking if new tab or window can be opened in javascript 跟踪单击是否打开新标签页/窗口的JavaScript - Javascript to track if a click opened a new tab/window 确定是否使用JavaScript打开了窗口 - Determine if window was opened using javascript 如何使用javascript强制在新标签页中打开链接 - how to force a link to be opened in a new tab using javascript 如何在每个新打开的选项卡或 window 中启动 JavaScript function 或同一 Z4C4AD5FCA2E303F74DBB1A4Z 页面? - How launch JavaScript function in every new opened tab or window of the same HTML page? 首次打开浏览器窗口/选项卡后,执行JavaScript代码 - Execute JavaScript code once a browser window/tab is opened for the first time 使用 window.open() function 打开已打开的选项卡而不重新加载已打开的选项卡 - To open the already opened tab using window.open() function without reloading the already opened tab
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM