2

Is there a way to open a new tab in a window that you have opened already, through JavaScript, from the parent window, but open the tab in the new window, not the parent window?

In other words, can you do this type of a thing in the same DOM from one JavaScript?

//this opens the new window
var windowOpened = window.open("html1.html", "", "width=400, height=200");
//this is where I would like to open a new tab in the window I opened above
windowOpened.open("html2.html","","_blank");

I'm fairly certain that the "_blank" is not valid, but it is there for an example. I'm hoping there has to be a way that will open the new tab in the window that was already opened, through javascript from another window.

I know I could use jQuery-ui and open a window that has tabs in it, that I can add tabs to or even remove a tab. But I'm needing an existing browser window to open a new tab in the window that I opened from the "parent" window.

Is this possible? If so how?

Matthew Dewell
  • 563
  • 7
  • 30
  • 1
    Possible duplicate of [Open a URL in a new tab (and not a new window) using JavaScript](http://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window-using-javascript) – Johannes Jander Mar 08 '16 at 13:38
  • This is not the same, as that is try to open a new tab in the same window as the JavaScript window, i.e. the "parent" window. In this one, I have window1, opening a new window, window2. Then I want to have the window1, open a new tab in window2. I hope that clarifies it a bit. – Matthew Dewell Mar 08 '16 at 14:21

2 Answers2

0

The parameter you used for the '_blank' is the name of the window. If you use the same name it will open in the same window.

windowOpened.open("html1.html","myWindow");

This will open in the same window:

windowOpened.open("html2.html","myWindow");

marcosspn
  • 376
  • 5
  • 14
  • I tried your response. It, first off, didn't work, with the "windowOpened.open()" command, on the first window open command, but I figured you just made a typo. I had tried the window name, yours being "myWindow", and it simply writes in the same tab of the new window, not a new tab in the new window. Note: the window name needs to be the second entry in window.open(). Thank you for the response though. – Matthew Dewell Mar 08 '16 at 14:17
  • Sorry. I read it fast and didn't get the part where you said new tab in the window2. You're right, the name is the second parameter. – marcosspn Mar 08 '16 at 14:56
0

OK, I got it to work this way, thanks to your help @marcosspn:

var window1 = window.open("html1.html", "tab1", "width=400, height=200");
window1.open("html2.html", "tab2");

Apparently the window names, declared in the window.open("url", "windowName", "options") command have to be different, but the var declared in the first window open, has to be used to open the new tab in the same window.

Hope this helps some more people. Yet, I have another issue, and that is how can I pass the window1 object to another function to use the already opened window. I'll work on that, now, but any advice on passing window objects would be helpful.

Thanks.

Matthew Dewell
  • 563
  • 7
  • 30
  • OK, I think I got the window object passing figured out. It was a typo. Watch out for capitalization of first letters in CAML case. ;o) I think what I want will work. Thank you all. – Matthew Dewell Mar 08 '16 at 16:09