oyvindkinsey/easyXDM — Issue #130: Getting access to the iframe right after instantiation of socket
Author: erkie
Created: 2011-10-13 09:47:46+00:00
State: open

In my app I'm using easyXDM.Socket to communicate between iframes on different domains. And the iframe generated by easyXDM.Socket is the iframe the user is navigating in. One problem that has annoyed me is that the iframe is not generated right away, and thus I can't add events to it, manipulate it, etc. So I can't write stuff like:

this.socket = new easyXDM.Socket({
remote: this.url,
container: this.container,
onMessage: function() {
console.log("got message");
}
});

var iframe = this.container.getElementsByTagName('iframe')[0];
// do stuff with iframe

That is because I have to wait for the onReady event which is called when the iframe is created. Wouldn't an option be that you can manually specify an iframe element yourself?

var iframe = document.createElement('iframe');
var socket = new easyXDM.Socket({
iframe: iframe,
remote: "http://foo/bar",
onReady: function() { /* iframe is prepped and ready for communication */ }
});