Iframe permission denied error when developing locally: what are my options?
Here's what's going on:
I have an application A
hosted on a.mycompany.com
and an application B
hosted on b.mycompany.com
Application A
contains an iframe containing a page contained in the application B
.
<!-- In A's index.html: -->
<iframe src="http://b.mycompany.com/something.html" >
I need to have开发者_开发百科 either the parent talk to the iframe or the iframe talk to the parent.
It works fine when it's on the server, but when I'm developping locally I have two different servers running on different ports so I have to access them via:
http://a.mycompanydev.com:1234
http://b.mycompanydev.com:5678
And this leads to a security error since you can't communicate using JS with an iframe from a different domain/subdomain or using a different port.
What can I do??
Related serverfault question: https://serverfault.com/questions/148171/how-to-map-localhost8080-to-simply-localhost
You can use fragment id messaging, which is a hack that uses window.location.hash (the part of the URL following #) to communicate. This test page has an example. There are also libraries such as Dojo that facilitate this.
If you only need to support recent browsers, you can use postMessage.
In addition to the postMessage and location hash that Matthew mentions above, you may want to consider using a proxy server running locally. The proxy server will listen on port 80 and forward to the appropriate target port based on the domain name specified in the http request. Then you just access your website normally on port 80 and things should work properly.
精彩评论