0

There is a strange requirement. I want to open a tab in a window which is previously opened using window.open(). So if the window is already open, next time open tab in that already opened window. I tried with the reference of the existing window to open a tab but it always opens a new window.

Thanks in advance.

user1000397
  • 33
  • 2
  • 9
  • Have a look at this [answer](http://stackoverflow.com/questions/528671/javascript-window-open-only-if-the-window-does-not-already-exist) this might help – Robin Carlo Catacutan Jul 15 '15 at 07:44

1 Answers1

0
var myWindow;

function openInWindow(url) {
    // If window does not exist, open one
    if(typeof myWindow === 'undefined') 
        myWindow = window.open(url, "My New Window");

    // If window was previously opened, reuse the same window
    else myWindow.location = url;
}

See also: https://developer.mozilla.org/en-US/docs/Web/API/Window/location

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
  • Thanks, but this will open the url in the same window. What I want is that the url should open in a new tab in myWindow. – user1000397 Jul 15 '15 at 07:51
  • I understand the OP wants to open a new window from some page (index.html) at first - keep the window open and when he clicks on another link in index.html open that new window in a new tab of the first window. – Dipak Jul 15 '15 at 07:58