简体   繁体   中英

Accessing Iframe Cross Origin

I have an HTML and an iframe inside it. when I try to access iframe contents it shows error like this.

" 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..?

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 ); But using the Access-Control-Allow-Origin header site B can give cross-origin access to specific requesting origins.

Site B can serve its pages to Site A with the following response header:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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