jasalguero
jasalguero

Reputation: 4181

Loading content of an external iframe locally

I´m doing an experiment locally to try to understand how the Cross Origin policy works with iframes:

According to the definition of the Cross Origin policy, if I try to access an element from the iframe from the page (now served from mytest.cnn.com), it should work, but I still get the same error "Blocked a frame with origin "http://mytest.cnn.com" from accessing a cross-origin frame".

I also tried changed the domain of the page to just "cnn.com", but I get the same result. Is there any special case applied because I´m serving the page from a local server?

Upvotes: 0

Views: 270

Answers (1)

Florian
Florian

Reputation: 66

The definition in the Same-origin policy description that you linked within your question says:

Two pages have the same origin if the protocol, port (if one is specified), and host are the same for both pages.

In your case the two hosts

  • edition.cnn.com
  • mytest.cnn.com

are not matching. Following the examples of the definition to different subdomains are no matching hosts.

If your iframe would point to a page on the same subdomain (i.e. mytest.cnn.com/iframe.html) everything should work.

Upvotes: 1

Related Questions