0

I have the following code (from related) that works for finding a reference to previously opened windows and closing them.

var playerUrl = 'http://my.player...';
var popupPlayer= window.open('', 'popupPlayer', 'width=150,height=100') ;
if(popupPlayer.location == 'about:blank' ){
    popupPlayer.location = playerUrl ;
}
popupPlayer.focus();

This also works across tabs in firefox, but in chrome it seems as if each separate tab is unaware of what is happening in the other tabs. I'd suspect this is due to each tab being a different process but is there anyway to bypass this?

So basically, if we open window A from page A in tab A, can we get a reference to window A from page B in tab B, and close it in chrome?

Related to:

Edit:

I found this that may be useful for messaging all other tabs to do the close action, though haven't tested in chrome: Sending a message to all open windows/tabs using JavaScript

Community
  • 1
  • 1
Menelaos
  • 23,508
  • 18
  • 90
  • 155

1 Answers1

2

I've used the PubSub functionality of jStorage before to do this. It's dependent on jQuery, so it may not be the best solution if you're not already using it, but you can check out the source code to see how it works.

Include jStorage on all tabs and the popup windows. On the popup windows, add this code:

$.jStorage.listenKeyChange('fireClose', function(){
    window.close()
});

Then, when you want to close it from any tab:

$.jStorage.set('fireClose', 'anything here, for simplicity');

You can use the second parameter to actually send data to the other windows if you want to have some more complicated interactions, but simply changing the key through jStorage.set is sufficient in this case.

http://www.jstorage.info/

freethejazz
  • 2,235
  • 14
  • 19
  • I'm asking for ways to close popup window that was created in `tab A` but should be closed from `tab B` if needed - in chrome . – Menelaos May 13 '13 at 17:02