Hunt
Hunt

Reputation: 8425

trying to open an existing window from different windows

I am trying reopen the existing window from different windows

For example ,

Inside window one, I am opening page one and on that page I have button, upon on click of that button I am opening another window with the name "Connect" using following code

   var connectWin = window.open("url to Connect page","Connect", "status=no,toolbar=no,menubar=no,location=no,directories=no,top=0,left=900,width=800,height=750");
   connectWin.name="Connect";

Now, in the same window one, I am traversing to different page (within same domain) and on this page I have another button and upon on click I am checking whether connect window is already open or not if yes, then I open the existing window otherwise thow an error

// code to take reference of an existing connect window
 var connectWnd = window.open('', 'Connect');


if( jQuery.type(connectWnd) === "undefined" || connectWnd.location.href === 'about:blank' ){         


    connectWnd.close();        
    $("#errorMessage").text("Connect page is not opened yet");


}else{

    //if connect is already open then post a message to that window
    connectWnd.postMessage(data);

}

The issue that i am facing is , if user open another page in a different window than I alway get Connect Page is not opened yet error.

It seems when user tries to access the page from different window i.e. window two than in that case window.open('', 'Connect'); fails. So is there a way to open an existing window from any window in the browser.

Upvotes: 1

Views: 59

Answers (1)

Dhananjai Pai
Dhananjai Pai

Reputation: 6015

There is no way to get access to other windows the user has opened in his browser from a web page since that can cause serious security issues. Also, it is impossible to redirect to another tab in the browser from one page (unless it is opened with window.open) since it has been abused by ad networks to force the browser to the other tab (earlier you could use alert() to force navigate the user to another tab)

The best solution to cover all edge cases may be to develop a browser extension and synchronize actions with a server to register open tabs (but even in that case, you cannot redirect him to a window on another browser!)

Upvotes: 2

Related Questions