0

I'm trying to get document from iframe using

document.getElementById('product-page').contentWindow.document

but I keep getting this error below, is there any way i can avoid the error?

VM1342:1 Uncaught DOMException: Blocked a frame with origin "URL" from accessing a cross-origin frame. at :1:54

Zahori
  • 400
  • 1
  • 3
  • 14
Phillip YS
  • 444
  • 1
  • 6
  • 29
  • This is CROS error, the url used in iframe might be in other domain as your parent page, check more on this link https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS – Vinod kumar G Jun 05 '18 at 09:44
  • Possible duplicate of [Access parent window from iframe (cross-domain)](https://stackoverflow.com/questions/9788328/access-parent-window-from-iframe-cross-domain) – Jacob Goh Jun 05 '18 at 09:45

2 Answers2

0

maybe its cannot because diffrent origin http

if diffrent hostname and port each iframe will be get CORS

For an explanation of CORS, please see this answer from programmers: https://softwareengineering.stackexchange.com/a/253043/139479

0

This is a restriction due to Same Origin Security Policy, If the iframe is from a different domain/port/protocol, you cannot access it via javascript.

Origin is considered different if at least one of the following parts of the address is not the same as your calling url:

<protocol>://<hostname>:<port>/path/to/page.html

But there is a way if you own both the websites you're trying to access,

Refer this answer for more info : SecurityError: Blocked a frame with origin from accessing a cross-origin frame

Ajanth
  • 1,820
  • 1
  • 16
  • 22