简体   繁体   English

访问iframe跨原点

[英]Accessing Iframe Cross Origin

I have an HTML and an iframe inside it. 我里面有一个HTML和一个iframe。 when I try to access iframe contents it shows error like this. 当我尝试访问iframe内容时,它显示了这样的错误。

" Uncaught DOMException: Blocked a frame with origin "http://parattapayyan.surge.sh" from accessing a cross-origin frame.
    at http://parattapayyan.surge.sh/test.html:14:24
(anonymous) @ test.html:14 "

how some chat companies like "intercom" and etc, accessing iframe from external server and components inside iframe..? 某些聊天公司(例如“对讲机”等)如何从外部服务器和iframe中的组件访问iframe?

When Site A tries to fetch content from Site B in a frame, by default, Site B's pages are not accessible due to security reasons(Read this :: https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy ); 当站点A尝试从框架中的站点B获取内容时,默认情况下,由于安全原因,站点B的页面不可访问(请阅读:: https://developer.mozilla.org/en-US/docs/Web/安全/ Same-origin_policy ); But using the Access-Control-Allow-Origin header site B can give cross-origin access to specific requesting origins. 但是使用Access-Control-Allow-Origin标头站点B可以跨域访问特定的请求来源。

Site B can serve its pages to Site A with the following response header: 站点B可以使用以下响应标头将其页面投放到站点A:

Access-Control-Allow-Origin: http://www.siteA.com

Without site B doing this, you won't be able to access site A in a frame. 没有站点B执行此操作,您将无法在框架中访问站点A。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM