Reputation: 1699
In a html document i append an iframe
in the body (no CORS, e.g. same url).
In the appended iframe
i attempt to do the same thing:
the nested iframe
element is successfully appended to the parent iframe
body, but the content won't load.
I googled without success for info about this issue,
i made plunk that simply shows it.
Can anybody tell me where's the problem?
Upvotes: 1
Views: 1589
Reputation: 1795
your code is doing what you are expecting, please try to inspect your page DOM, when you press the button the child iframe is added inside you parent iframe.
BUT:
the browser do not display an iframe inside an iframe with the same SRC, this is becouse the iframe loaded has the same source, this script else works fine becouse the url is changed every time appending a querystring
document.querySelector('button')
.addEventListener('click',function(){
var d = new Date();
var n = d.getTime();
var iframe = document.createElement('iframe');
iframe.setAttribute('src', location.href + "?" + n );
iframe.style.width = '100%';
iframe.style.height = '800px';
document.body.appendChild(iframe);
})
Upvotes: 2