Is there a limitation on an IFRAME containing another IFRAME with the same URL?
Looks like a sensible browser security mechanism to prevent an infinite loop of nested iframes (even though in your case it wouldn't be infinite).
In any case, a simple workaround could be to add a useless query parameter to the url, making the browser think the page loaded isn't identical, but really it is.
So instead of your current function add()
, something like this (I went all out so id
doesn't polute the global namespace):
var add = (function(){
var id = 0;
return function(){
var f = document.createElement('iframe');
f.src = 'addRemoveFrames.html?useless=' + id++;
document.getElementById('frameContainer').appendChild(f);
};
})();
Here is an official reference: Implementing HTML Frames - W3C Working Draft 31-Mar-97. The heading is 'Infinite Recursion' and states that if the src
is equal to the parent URL, it should be treated as empty.
I would recommend the technique davin
uses, or use pure DOM to create nested elements instead of IFRAME
s, which would make programmatic changes easier and potentially use less memory, as well as avoiding that issue with delayed loading.