[英]Call JavaScript function from remote server
I tried to call JavaScript function exist on some server(server1) from another server(server2) and I got this error: 我试图从另一台服务器(server2)调用某些服务器(server1)上的JavaScript函数,我收到此错误:
Unsafe JavaScript attempt to access frame with URL https://server1/ from frame with URL https://server2/ . 不安全的JavaScript尝试与URL访问框架的https://服务器1 /从URL框架的https://服务器2 / 。 Domains, protocols and ports must match.
域,协议和端口必须匹配。
I used JSP, Java, JavaScript and tomcat7, is there any way to solve this problem? 我用过JSP,Java,JavaScript和tomcat7,有什么方法可以解决这个问题吗? any help will be appreciated.
任何帮助将不胜感激。
Yes, must add a cross-origin rule to the header of your javascript file, which allows access from your other server. 是的,必须在您的javascript文件的标题中添加跨域规则,以允许从其他服务器进行访问。
Otherwise, your Browser doesn´t let you do that. 否则,您的浏览器不允许您这样做。
You can look at the answer of this Question: XmlHttpRequest error: Origin null is not allowed by Access-Control-Allow-Origin 你可以看一下这个问题的答案: XmlHttpRequest错误:Access-Control-Allow-Origin不允许使用null
It should tell you how to do it. 它应该告诉你如何做到这一点。
As described you are subject to the Same Origin Policy, this is designed to protect users. 如上所述,您遵循同源策略,旨在保护用户。 Google have a good write-up: http://code.google.com/p/browsersec/wiki/Part2 .
谷歌有一个很好的文章: http : //code.google.com/p/browsersec/wiki/Part2 。
There are several typical approaches to working around this: 有几种解决此问题的典型方法:
I've not tried http://easyxdm.net/wp/ 我没试过http://easyxdm.net/wp/
There are improvements coming, like cross document messaging in HTML5 有一些改进,比如HTML5中的跨文档消息传递
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.