PDA

View Full Version : Probelm about creating DIV in parent window from child window



kingfly2000
02 Jan 2010, 12:07 AM
I have a probelm about creating DIV in parent window from child window. following code works find in IE8, but it does not work in IE7 and 6

------------------------------------------
aaa.html

<html>
<head>
<title>aaa</title>
</head>
<body>
<iframe src=bbb.html height=0 width=0></iframe>
</body>
</html>
-------------------------------------------
bbb.html

<script type="text/javascript">
var objdiv = document.createElement("DIV");
objdiv.id = "testdiv";
objdiv.innerHTML="bbb";
parent.document.body.appendChild(objdiv);
</script>

Learningcn
04 Jan 2010, 05:37 PM
appendChild() doesn't work in IE(6,7) with iframe's parent/child
there's other ways:
1. call a parent's function
2. use innerHTML

i.e.

---bbb.html---

<script type="text/javascript">
window.parent.document.body.innerHTML='<div id="testdiv">bbb</div>';
</script>