Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Communication between windows/tabs with JavaScript [duplicate]

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.

Edit: Why was this marked as duplicate when this was asked before the other question?

like image 863
James T Avatar asked Feb 13 '11 23:02

James T


People also ask

Is localStorage shared between tabs?

The main features of localStorage are: Shared between all tabs and windows from the same origin. The data does not expire. It remains after the browser restart and even OS reboot.


1 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)

like image 67
James T Avatar answered Oct 08 '22 09:10

James T