2

Having an iframe embedded on a site

<iframe src="iframe.html" id="myIFrame" onload="frameOnload()"></iframe>
...
<script>
...
var abc = window.document.getElementById("myIFrame").contentWindow
...
</script>

I got an error Permission denied to access property "document" on cross-origin object on line

var abc = window.document.getElementById("myIFrame").contentWindow

Even if the iframe is located on same domain ("localhost") as the parent site. To get the code working i have to explicitly set the iframe domain like so window.document.domain = "localhost" in the iframe script tag.

My question is why we heve to set the iframe domain explicitly while the parent site and iframe itself live on the same domain?

Mulligun81
  • 119
  • 1
  • 13
  • May be of use for you: https://stackoverflow.com/questions/36333978/error-permission-denied-to-access-property-document – Pete Oct 20 '17 at 11:57

0 Answers0