文件代码如下:
(1) node.jsp
<script type="text/javascript">
function Node() {
this.id = id;
this.pid = pid;
};node=new Node();//定义了一个对象node
</script>(2) nodeTest.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body><div id="ad" class="dtree">
<iframe id="if1" src="node.jsp" width="250" height="200" frameborder="0" MARGINWIDTH="0" MARGINHEIGHT="0">
</iframe>
</div>
<script type="text/javascript">
document.getElementById("if1").contentWindow.document.node.id=2;//失败,访问不到node.jsp中脚本定义的对象node
</script>
(1) node.jsp
<script type="text/javascript">
function Node() {
this.id = id;
this.pid = pid;
};node=new Node();//定义了一个对象node
</script>(2) nodeTest.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body><div id="ad" class="dtree">
<iframe id="if1" src="node.jsp" width="250" height="200" frameborder="0" MARGINWIDTH="0" MARGINHEIGHT="0">
</iframe>
</div>
<script type="text/javascript">
document.getElementById("if1").contentWindow.document.node.id=2;//失败,访问不到node.jsp中脚本定义的对象node
</script>
document.getElementById("if1").contentWindow.node is undefined
var doc=win.document;
doc.onreadystatechange=function() {
if(doc.readyState=="complete") {
win.node.id=2
}
}