Welcome Guest, you are in: Login

easyXDM - cross-domain messaging made easy




RSS RSS

Navigation



Search the wiki
»

PoweredBy
easyXDM is a javascript library that uses available techniques to provide a means of transporting messages and/or method calls between windows in different domains.

The library is currently implementing postMessage for browsers that supports this and will fall back to using the IFrame URL Technique for all others, including IE6.

The library uses named channels, and can be set to only allow certain domain names for communication.

Messages are passed between the domains as strings and there are no known security risks involved. Only methods that you explicitly expose will be available for invokation.

Please use this blog post for commenting.


Perfect for API providers

This is perfect if you plan to provide a client-side API on your web site as you can expose a method in very few lines of code. And also, you dont have to provide a full client library to the consumers, you can just tell them the location of your easyXDM-endpoint, and then show them the interface they will have to implement - and this can be as small as 1 line for a one-method interface!

Example

At http://provider.easyxdm.net/p/ we have an easyXDM-endpoint that exposes the following interface
{
    remote: {
        doMath: {
        } // Requires two numbers as arguments
    }
}
In short this means that it exposes one method called doMath, and that it requires no methods exposed by the consumer.
The entire code needed to implement this is
var remote = new easyXDM.Interface({}, {
    local: {
        doMath: {
            method: _doMath // Private method located in the document
        }
    }
});
All a consumer needs to do to be able to call the doMath method is to create a document containing the following
var remote = new easyXDM.Interface({
    local: "/hash.html",
    remote: "http://provider.easyxdm.net/p/" // The location of the easyXDM-endpoint
}, {
    remote: {
        doMath: {}
    }
});
And then they would be able to call the doMath method using
                        remote.doMath(5,7,function(result){
                        	// Consume the result
                        }
                       
This can be seen in action at http://consumer.easyxdm.net/c/.
Several more interesting demos can be found in the official easyXDM API Documentation.

If you want to test this you can simply extract consumer.zip to your own domain and it should all work.

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam.

Copyright © Øyvind Sean Kinsey