In one of the projects I am faced with problem of the java scripts execution on different domains.
After advice from one of team leaders, the solution was found and it was a quite simple.
For example, we have A domain with frame that point to domain B which is to call javascript function in domain A.
If you simply call a window.parent.funcame you will get exception. So what can we do ?
It is very simple – in domain B we create frame to domain A and then we
try to execute a function on domain A as window.parent.parent.fucname
and how we can see function is executed succesufully.
So this script does this operation automatically without requiring knowledge of java script.
Credits:
Nir Levy
Usage:
Domain A:
Main file:
<html>
<head><title>domain_a</title></head>
<body>
<script>
function showmelove(text)
{
alert(text);
}
</script>
... some content here ...
<iframe id="hpel" height="100" frameborder="0" width="100%" scrolling="0" title="" src="http://domain_b/iframe.html" style="height: 194px;"></iframe>
... some content here ...
</body>
</html>
Exec file:
<html>
<body>
<script type="text/javascript" src="crossdomain_server.js"></script>
<script type="text/javascript">
crossdomain.server().init();
</script>
</body>
</html>
Domain B:
<html>
<head>
<script src="crossdomain_client.js" type="text/javascript" ></script>
<script>
crossdomain.client("frame").init("http://www.domain_a/iframe.html");
function sendText() {
crossdomain.client("frame").callfunc("showmelove",{mesasge: "'hello world'"});
}
</script>
</head>
<body>
<div id="allBodyDiv">
some content goes here...
<input type="button" value="send" onclick="sendText()" />
</div>
</body>
</html>
Download
: CrossDomain
来源: http://www.emposha.com/javascript/cross-domain-javascript-execution-library.html
分享到:
相关推荐
前端和后端都可以需要,给yapi测试集合的时候使用
cross-request 3.1 YApi 跨域请求 谷歌浏览器
使用YApi,在线调取接口时,需要在谷歌浏览器安装插件。解压之后,将cross-request.crx文件拖到谷歌浏览器的扩展程序页面,确认即可。
安装npm我跨域存储用法主持人var createHost = require ( 'cross-domain-storage/host' ) ;主机(allowedDomains) 使用允许的域数组进行调用。 var storageHost = createHost ( [ { origin : 'http://www.foo.com' ...
用postMessage解决跨域问题的完整demo,下载后通过node启动可直接测试,使用前请仔细阅读readme文件 可参考博客:https://blog.csdn.net/github_39274378/article/details/81671363
B域(子页面)中的文件crossdomain.js 实现跨域的关键文件,用于动态生成跳转的iframe;var crossDomain = new CrossDomain('<A>/cross_domain_transfer.html'); //初始化跨域类,传入目标域的跨域跳转页面...
cross-domain 跨域集成方案 点击主页 send Random 按钮 点击子页(引用页) popup 按钮 1 添加依赖 <groupId>com.os.cross-domain</groupId> <artifactId>cross-domain-lib <version>1.0-SNAPSHOT 2 添加映射 2.1...
php-cross-domain-proxy, 跨域请求的PHP代理 PHP CORS代理 以前称为"php跨域( AJAX ) 代理PHP CORS代理是一个简单的PHP脚本,允许跨域请求。 它可以以用来访问第三方网站的资源当不能在目标网站 换句话说,上启用...
在web开发中,跨域问题是经常遇到的,但是由于浏览器同源策略的限制,不同域之间属性和操作是无法直接交互的。本次讨论iframe和父页面的消息通信。
在多个任务域的情况下,这些算法需要任务间映射以促进跨域的知识转移。但是,当前没有通用的方法来学习任务间映射,而不需要RL设置中通常不存在的背景知识,也不需要对状态和动作的大小以指数形式进行的任务间映射的...
跨域的解决方案有多重JSONP、Flash、Iframe等,当然还有CORS(跨域资源共享,Cross-Origin Resource Sharing)
在之前的分享的跨域资源共享的文章中,有提到要注意跨域时,如果要发送Cookie,Access-Control-Allow-Origin就不能设为*,必须指定明确的、与请求网页一致的域名。在此次项目开发中与他人协作中就遇到此类问题。 ...
最新cross-request3.0插件下载,下载完成后解压,在Chrome中选择加载已解压的插件进行安装。
cross-domain-sso:跨域单点登录案例研究
cross-domain一个利用html5的跨域api postMessage解决多iframe跨域通信的js框架背景最初公司只有一个系统来做销售,随着公司业务越来越多,搭建很多类似的系统(这些系统本来是没有任何关系的,每个系统目前都非常...
flash跨域访问策略。渗透测试时检查crossdomain.xml配置信息,应当重点检查allow-access-from=*、allow-...特别注意参数为*和all,当站内没有crossdomain.xml时将不允许flash跨域访问。不会导致漏洞
之前的资源被系统强制提升到30分了,降不下来,只能重新上传一份了。
cross-request YApi 跨域请求