Closed Bug 400284 Opened 17 years ago Closed 17 years ago

Content of dynamically created iframe disappear when using insertBefore function

Categories

(Firefox :: General, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 254144

People

(Reporter: alex.cheushev, Unassigned)

Details

User-Agent:       Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; InfoPath.2)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7

I create iframe in some DIV using JS document.createElement("IFRAME") and write there some content using el.contentWindow.document.open() etc.
After that if I use insertBefore and move this div with iframe to another place in DOM I'll loose everything in frame (I see empty HEAD and BODY in iframe).

Reproducible: Always

Steps to Reproduce:
1.Create iframe using JS
2.Write some content to iframe
3.Move iframe to another place in the DOM
4.Check that you lost all iframe content
Actual Results:  
You see empty iframe without any content.

Expected Results:  
You see content that you created in the iframe.

<html>
<head>
<script>
function swit() {
	var d = document.getElementById("par");
	var d1 = d.getElementsByTagName("DIV")[0];
	var d2 = d.getElementsByTagName("DIV")[1];
	
	d.insertBefore(d2,d1);
}

function setc() {
	var d = document.getElementById("par");
	
	var el = document.createElement("STRONG");
	el.innerHTML = "111111";
	el.style.color = "green";
	d.getElementsByTagName("DIV")[0].appendChild(el);
	var el = document.createElement("IFRAME");
	d.getElementsByTagName("DIV")[0].appendChild(el);
	with (el.contentWindow.document) {
		open();
		write("1111111111111111");
		close();
	}
	
	var el = document.createElement("STRONG");
	el.innerHTML = "222222";
	el.style.color = "red";
	d.getElementsByTagName("DIV")[1].appendChild(el);
	var el = document.createElement("IFRAME");
	d.getElementsByTagName("DIV")[1].appendChild(el);
	with (el.contentWindow.document) {
		open();
		write("22222222222222222");
		close();
	}
}
</script>
</head>
<body onload="setc();">

<div id="par">
	<div id="1"></div>
	<div id="2"></div>
</div>

<input type="button" onclick="swit();" value="SW" />

</body>
</html>
Calling insertBefore reloads the iframe but content created with script can't be reloaded...
Status: UNCONFIRMED → RESOLVED
Closed: 17 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.