How can I have two tabs (or windows) that are on the same domain be able to talk to each other without having to have one window instance the other.
-
Some news about the topic: http://stackoverflow.com/questions/19125823/how-is-it-possible-to-share-single-js-resource-between-browser-tabs/19165781#19165781 BNC Connector is still an option, a new option is intercom.js which uses localStorage, and another option is using shared webworkers. – inf3rno Oct 03 '13 at 23:05
4 Answers
I found a way, I can make two flash movies on each page with LocalConnection to invoke JavaScript on the other page using externalinterface.
Put this in a AS3 swf, this is the receiver:
import flash.external.ExternalInterface;
import flash.net.LocalConnection;
var mLocalConnection:LocalConnection;
mLocalConnection = new LocalConnection();
mLocalConnection.connect("xivioview");
mLocalConnection.client=this;
function recieveText(textRecieved):void {
ExternalInterface.call(textRecieved);
};
And the sender swf:
import flash.external.ExternalInterface;
import flash.net.LocalConnection;
function sendtoview(con,val):String {
//create local connection for sending text
var sending_lc:LocalConnection;
sending_lc = new LocalConnection();
sending_lc.send("xivioview", "recieveText", val);
return "kk"
}
ExternalInterface.addCallback("sendtoview", sendtoview);
This is set up for one-way, and the javascript to use it:
document.getElementById("youembeddedobject").sendtoview("xivioview","alert('Hai!')")
That will execute that JavaScript code in the receiver's tab, but it won't execute until you go back to that tab (I already asked a question why, and have no response yet)

- 3,292
- 8
- 40
- 70
-
1Any links about how you did this? Is this cross browser supported? – samarjit samanta Mar 01 '11 at 01:34
-
There's the source. It should work for every single browser, btw you can change the "xivioview" text, it's the connectionID. – James T Mar 01 '11 at 17:17
-
1The same holds for Silverlight. There is a LocalConnection object which enables to communicate locally between Silverlight controls across a local machine. – Palantir May 31 '11 at 14:27
I would just have a javascript execute in the page load that would continuously poll (window.setInterval) the sessionStore for a flag saying someone sent me a message then read that message from the sessionStore and then do whatever is required.

- 21
- 5
Communicating between different JavaScript execution context was supported even before HTML5 if the documents was of the same origin. If not or you have no reference to the other Window
object, then you could use the new postMessage API introduced with HTML5. I elaborated a bit on both approaches in this stackoverflow answer.

- 1
- 1

- 18,072
- 9
- 87
- 115
The only way I can think of would be to use XHR. Each window/tab communicates with the server, which in turn communicates back with other windows, pretty much the same way gmail chat works. Except that you would have 2 windows on the same client, rather than 1 window on 2 clients.

- 26,399
- 1
- 23
- 24