1

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

Sanoj Sen
  • 17
  • 1
  • 1
  • 3
  • 2
    Possible duplicate of [SecurityError: Blocked a frame with origin from accessing a cross-origin frame](https://stackoverflow.com/questions/25098021/securityerror-blocked-a-frame-with-origin-from-accessing-a-cross-origin-frame) – Deepak Keynes Dec 30 '17 at 07:25

1 Answers1

1

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.

  • Not for iframes... See https://stackoverflow.com/questions/25098021/securityerror-blocked-a-frame-with-origin-from-accessing-a-cross-origin-frame – RPinel Oct 12 '18 at 13:58
  • 1
    @RPinel - is there any solution to this for iframes? – Ask P Feb 03 '20 at 19:16
  • Actually, I just want to scroll the webpage, iframe.contentWindow.scrollTo ... – Zhang Apr 09 '21 at 06:43