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?