0

I tried to call JavaScript function exist on some server(server1) from another server(server2) and I got this error:

Unsafe JavaScript attempt to access frame with URL https://server1/ from frame with URL https://server2/ . Domains, protocols and ports must match.

I used JSP, Java, JavaScript and tomcat7, is there any way to solve this problem? any help will be appreciated.

Sean Kinsey
  • 37,689
  • 7
  • 52
  • 71
user670934
  • 1
  • 1
  • 2

3 Answers3

2

Yes, must add a cross-origin rule to the header of your javascript file, which allows access from your other server.

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

It should tell you how to do it.

Community
  • 1
  • 1
Van Coding
  • 24,244
  • 24
  • 88
  • 132
  • thanks for answer, I tried to put this in the header response.addHeader("Access-Control-Allow-Origin","*"); but it didn't solve the problem. how can I add it? do you have any useful links please. – user670934 Mar 22 '11 at 10:28
  • This only works for enabling CORS (cross domain resource sharing) - not for enabling cross domain access between windows. – Sean Kinsey Mar 22 '11 at 10:44
0

Take a look at easyXDM - it provides an RPC feature allowing you to call methods across the Same Origin Policy.

Take a look at one of the demo's here

Sean Kinsey
  • 37,689
  • 7
  • 52
  • 71
0

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.

There are several typical approaches to working around this:

  1. jquery has a getJson or jsonp type of function. most other js libs have something similar. They use a dynamic Script tag, suitable for GET requests from other domains.
  2. Create a servlet on domain1 that proxies to domain2 - allows unrestricted HTTP methods and use of XmlHTTPRequest.

I've not tried http://easyxdm.net/wp/

There are improvements coming, like cross document messaging in HTML5

bdargan
  • 1,309
  • 8
  • 16