简体   繁体   English

在浏览器中的两个窗口/选项卡之间切换

[英]Switch between two windows / tabs in a browser

I am able to move (window.open) from page "A" on parent window to page "B" on child window but not the other way round. 我可以将(window.open)从父窗口上的页面“ A”移动到子窗口上的“ B”页面,但不能反过来。 I tried window.opener.alert but it only works on chrome and opera. 我尝试了window.opener.alert,但它仅适用于Chrome和Opera。 I cannot use history.go(-1) history.go(1) because there is a login page between page A and B 我不能使用history.go(-1)history.go(1),因为在页面A和页面B之间有一个登录页面

I need it to work on especially Safari. 我需要它特别是在Safari上工作。 How can i achieve this. 我怎样才能做到这一点。 Is there another way to do this? 还有另一种方法吗? A solution without the alert will even be better. 没有警报的解决方案甚至会更好。 Thanks for the help 谢谢您的帮助

page "A" 页面“ A”

var pop;
function openPageB() 
{
    if (typeof (pop) == 'undefined' || pop.closed)
    {
        pop = window.open('pageb.php?', 'bWindow');
    }
    else
    {
        pop.focus();
    }
}

Page "B" 页面“ B”

function openPageA()
{

    //window.opener.focus();
    window.opener.alert('Child window');

}

After days and hours of trying to solve this with little success, i finally found a way around it which works for me. 经过数天和数小时的尝试来解决这一问题,但收效甚微,我终于找到了解决之道。 I thought of putting it here for other who may also be searching for solution. 我想把它放在这里,供其他可能也在寻找解决方案的人使用。

On Page "B", since window.opener.alert('---') does not open/focus the parent tab on all browsers, i replaced that line with self.close() which will close child tab ie Page "B" and focus the Parent tab. 在页面“ B”上,由于window.opener.alert('---')并未在所有浏览器上打开/突出显示父选项卡,因此我用self.close()替换了该行,这将关闭子选项卡,即页面“ B” ”,然后突出显示“父级”标签。

Clicking on the Button that call the function openPageB() on the parent tab will always open the child tab again. 单击在父选项卡上调用函数openPageB()的按钮将始终再次打开子选项卡。 This is the edited code for returning to the parent tab. 这是返回到父选项卡的编辑代码。 Enjoy using it. 喜欢使用它。

function openPageA()
{

    self.close() //this line did it

}

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

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