开发者

How to open child window in another child windows's tab in javascript?

I am struggling over here with a simple problem in javascript.

what I want to do:

1. open a popup(p1) from main page.

2. open another popup(p2) from first popup(p1).

3. now I want to open popup from p2 in p1's tab.

I am using following code:

var test = null;
// open first popup(p1) from main page
function openpopup1(URL,id) {
    test = eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=850,height=650,left = 520,top = 300');");
}

// open second popup(p2) from p1 popup
function openpopup2(URL,id){
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=650,height=300,left=650,top = 280');");
}

// now open popup into p1's tab from p2 popup
function openpopupTop1stab(){
    var newTab = window.open("tab.html");  
    window.test.opener(newTab); 
    // this code is not working
}

How can I 开发者_如何学Gosolve this problem?


I'm not sure I understand the question. If you actually want to open a tab in a window, as mentioned, that's not possible. The browser does not expose that ability to pages. You could possibly make your own tab-like controls, by having divs that are shown and hidden by clicking a button near the top of a page, and you could have a separate window update or change those "tabbed" divs (which could contain iframes if you want to show whole pages within them). You would need to keep references to the opened windows so that you can communicate between them.

If you simply want to control what content appears in windows or tabs, that is much easier.

The second argument to 'window.open' is the window name. If you open another page with that window name or click on a link with a 'target' attribute with that name, the new page will open in that existing window.

So you could do:

window.open("p1.html", "p1");
window.open("p2.html", "p2");

Then later, if you do:

window.open("p3,html", "p1");

it will open the page "p3.html" in the window or tab initially opened for "p1.html".

Also works:

<a href="p3.html" target="p1">Open in p1 tab/window</a>

(Note: The special window name "_blank" means to always open a new window)


That is not possible. JavaScript has no concept of "tabs". It's purely the browser's (or due to browser configuration the user's) decision how to display a "window" opened with window.open.


I notice this is old but there are now chrome extensions that force opening new windows as new tabs. If you go here, it's an extension I use myself and it works great.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜