There is a website (S), that contains an iframe (A), that displays my site. What I need, is to add an iframe (B) from my site to the parent page (S) with javascript. I coded something, but this adds the new iframe (B) to the iframe’s (A) content, not to the parent’s (S)
The website (S) is not the same domain.
Code on my site:
<script>
function GetFrame()
{
ifrm = window.document.createElement("IFRAME");
ifrm.setAttribute("src", "http://stackoverflow.com/");
ifrm.setAttribute("style", "position: absolute; left: 0px; top: 0px; width: 100%; height: 25%; border: none;");
window.document.getElementsByTagName('BODY')[0].appendChild(ifrm);
}
</script>
<img src="image.jpg" onload="GetFrame()"/>
You can’t do this because of the Same Origin Policy.
If you want to add iframe B to S, you’ll need S to run the script for you, either by fetching it with
<script src="SCRIPT_URL"></script>or by defining it inline with<script>YOUR_SCRIPT</script>.