easyXDM - easy Cross-Domain Messaging
=====================================
easyXDM is a Javascript library that enables you as a developer to easily work around the limitation set in place by the Same Origin Policy, in turn making it easy to communicate and expose javascript API's across domain boundaries.
**Some of the goals for the project are that it should**
* be easy to use!!!
* be self contained, <del>no dependencies</del> (Now requires Flash for the FlashTransport) (not counting JSON)
* be light weight
* be flexible
* have good code quality (uses jslint etc)
* have good documentation
* be the best xdm-library in existence
How easyXDM works
---------------
At the core easyXDM provides a transport stack capable of passing string based messages between two windows, a **consumer** (the main document) and a **provider** (a document included using an iframe).
It does this by using one of several available techniques, always selecting the most efficient one for the current browser.
For all implementations the transport stack offers bi-directionality, reliability, queueing and sender-verification.
Using JavaScript only (no Flash, Silverlight, extra html files etc) easyXDM provides the following browsers with stacks with latency of less than 15ms:
* IE8+ - using the PostMessageTransport
* Opera 9+ - using the PostMessageTransport (support for both Operas old standard and the HTML5 standard)
* Firefox 1-2 - using the FrameElementTransport
* Firefox 3+ - using the PostMessageTransport
* Safari 4+ - using the PostMessageTransport
* Chrome 2+ - using the PostMessageTransport
In browsers not mentioned here, and not supporting the *postMessage* API, the following transports will be used, depending on support and configuation:
* FlashTransport - Requires Flash 6+ and the swf property to be configured and will load a single swf into the document that functions as a factory. The swf has been audited by Google Security researchers.
* NameTransport - Requires an html-file (name.html) to be hosted on each of the two domain. The cache-directives in the file allows the transport to pass messages with speeds similar to postMessage without incurring extra HTTP-requests.
* HashTransport - If no other transport can be used, then the HashTransport will be used.
How to use easyXDM
------------------
When using easyXDM you first load the *consumer* document and then **let easyXDM load** the *provider*. This is by default done in a hidden iframe, but you can also configure easyXDM to display the iframe in a specific container, and with a specific style attached.
The library provides two main object types that utilize this transport stack:
The easyXDM.Socket
-----------------
.. is a thin wrapper around the transport stack and lets you send strings between the consumer and the provider.
To set up a simple Socket this is what you will need to add to the *consumer*
```javascript
var socket = new easyXDM.Socket({
remote: "http://path.to/provider/", // the path to the provider
onMessage:function(message, origin) {
//do something with message
}
});
```
And this is what's needed for the *provider*
```javascript
var socket = new easyXDM.Socket({
onMessage:function(message, origin) {
//do something with message
}
});
```
Use this for sending the strings to the other end:
```javascript
socket.postMessage("hello world");
```
In addition the following config properties can be set for both consumer and provider
* `onReady` - If you set this to a function, then this will be called once the communication has been established.
* `local` {String} - To enable the NameTransport as a fallback, set this to point to the `name.html` file on the current domain.
* `swf` {String} - To enable the FlashTransport for IE6/7 you need to point this towards your `easyxdm.swf` file. The swf must reside on one of the two domains (consumer and provider can use its own copy), or on a shared CDN used by both the consumer and provider.
* `swfNoThrottle` {Boolean} - Set this to true if you want to have the swf/iframe placed visibly (20x20px top right corner) in order to avoid being throttled in newer versions of Flash
* `swfContainer` {String || DOMElement) - Set this if you want to control where the swf is placed.
These properties can be set only on the consumer
* `lazy` {Boolean} - If you set this to `true` then the iframe will not be created until the first use of the Socket
* `container` {String || DOMElement} - Set this to an id or element if you want the iframe to be visible for interaction.
* `props` {Object} - The key/value pairs of this object will be deep-copied onto the iframe. As an example, use `props: {style: {border: "1px solid red"} }` to set the border of the iframe to 1px solid red.
* `remoteHelper` {String} - To enable the NameTransport as a fallback, set this to point to the `name.html` file on the provider.
* `hash` {Boolean} - Whether to pass the setup data using the hash instead of using the query. This is mainly useful in scenarios where query arguments affects efficient caching or where the providers HTTP server does not support URL's with query parameters. Using the hash is not compatible with hash based history managers etc.
These properties can be set only on the provider
* `acl` {String || String[]} Use this to only allow specific domains to consume this provider. The patterns can contain the wildcards ? and * as in the examples 'http://example.com', '*.foo.com' and '*dom?.com', or they can be regular expressions starting with ^ and ending with $. If none of the patterns match an Error will be thrown.
A socket can be teared down (iframe removed etc) using
```javascript
socket.destroy();
```
The easyXDM.Rpc
---------------
... constructor lets you create a proxy object with method stubs and uses JSON-RPC to invoke these methods and return the responses.
The Rpc uses the same transport stack as the Socket, and so **uses the same config properties**.
To set up a simple Rpc this is what you will need to add to the *consumer*
```javascript
var rpc = new easyXDM.Rpc({
remote: "http://path.to/provider/" // the path to the provider
},
{
local: {
helloWorld: function(successFn, errorFn){
// here we expose a simple method with no arguments
// if we want to return a response, we can use `return ....`,
// or we can use the provided callbacks if the operation is async
// or an error occurred
}
},
remote: {
helloWorld:{
// here we tell the Rpc object to stub a method helloWorld for us
}
}
});
```
Call the methods like this
```javascript
rpc.helloWorld(1,2,3, function(response){
// here we can do something with the return value from `helloWorld`
}, function(errorObj){
// here we can react to a possible error
};
```
And this is what's needed for the *provider*
```javascript
var rpc = new easyXDM.Rpc({},
{
local: {
helloWorld: function(one, two, thre_args, successFn, errorFn){
// here we expose a simple method with three arguments
// that returns an object
return {
this_is: "an object"
};
}
},
remote: {
helloWorld:{
// here we tell the Rpc object to stub a method helloWorld for us
}
}
});
```
Call the methods like this
```javascript
rpc.helloWorld(); // easyXDM automatically changes it's behavior depending on the presence of callback methods for `success` and for `error`.
```
The Rpc configurations `local` and `remote` properties can be left out if empty. Both properties can have multiple methods defined.
When calling the stubs you can provide up to two callback
没有合适的资源?快使用搜索试试~ 我知道了~
easyXDM.zip_opera_跨域
共613个文件
gif:254个
html:64个
js:50个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 200 浏览量
2022-09-19
19:36:10
上传
评论
收藏 8.6MB ZIP 举报
温馨提示
javascript跨域访问的类,支持所有主流浏览器,包括IE6+,FileFox,Chrome,Safari,Opera等,包含了目前所有的主流跨域方式
资源推荐
资源详情
资源评论
收起资源包目录
easyXDM.zip_opera_跨域 (613个子文件)
ant 10KB
antRun 861B
Main.as 8KB
net.easyxdm.flash.as2proj 2KB
glossary.aspx 960B
glossary.aspx 960B
upload_handler.aspx 373B
upload_handler.aspx 373B
ant.bat 8KB
antRun.bat 2KB
lcp.bat 1KB
build.bat 20B
envset.cmd 4KB
antenv.cmd 3KB
ant.cmd 3KB
runrc.cmd 2KB
publish.cmd 109B
documentation.cmd 83B
package.cmd 77B
build.cmd 69B
ext-all.css 134KB
shCore.css 7KB
grids.css 7KB
style.css 6KB
docs.css 6KB
shThemeMoxieDoc.css 4KB
general.css 3KB
print.css 3KB
jquery.treeview.css 2KB
reset.css 1KB
collapser.css 814B
reset.css 487B
prettify.css 469B
welcome.css 372B
easyTest.css 150B
easyTest.css 150B
extanim64.gif 6KB
tool-sprites.gif 4KB
btn.gif 4KB
tip-sprite.gif 4KB
error-tip-corners.gif 4KB
extanim32.gif 3KB
blue-loading.gif 3KB
large-loading.gif 3KB
block-bottom.gif 3KB
tools-sprites-trans.gif 3KB
group-cs.gif 2KB
search-trigger.gif 2KB
tabs-sprite.gif 2KB
loading-balls.gif 2KB
extjs.gif 2KB
tb-sprite.gif 2KB
checkbox.gif 2KB
clear-trigger.gif 2KB
tree-bg.gif 2KB
welcome-bg.gif 2KB
radio.gif 2KB
trigger.gif 2KB
icon-error.gif 2KB
tb-xl-btn-sprite.gif 2KB
collapse-bg.gif 2KB
icon-question.gif 2KB
date-trigger.gif 2KB
e-handle.gif 2KB
icon-info.gif 2KB
trigger-tpl.gif 1KB
icon-warning.gif 1KB
sort-hd.gif 1KB
gradient-bg.gif 1KB
gradient-bg.gif 1KB
corners-sprite.gif 1KB
tab-btm-left-bg.gif 1KB
tab-btm-inactive-right-bg.gif 1KB
white-corners-sprite.gif 1KB
btn-sprite.gif 1KB
s-handle.gif 1KB
scroll-right.gif 1KB
scroll-left.gif 1KB
grid3-hd-btn.gif 1KB
tb-btn-sprite.gif 1KB
wait.gif 1KB
scroller-bg.gif 1KB
hd-sprite.gif 1KB
bg.gif 1KB
row-check-sprite.gif 1KB
e-handle-dark.gif 1KB
s-handle-dark.gif 1KB
pkg-open.gif 1KB
pkg-closed.gif 1KB
pick-button.gif 1KB
print.gif 1KB
forum.gif 1KB
drop-yes.gif 1016B
drop-yes.gif 1016B
docs.gif 1016B
corners-blue.gif 1010B
expand-all.gif 1009B
example.gif 1008B
corners.gif 1005B
folder.gif 1003B
共 613 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
我虽横行却不霸道
- 粉丝: 73
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功