日期:2014-05-16  浏览次数:20432 次

为什么window的父窗口为空?
我写了如下的javascript

<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   HTML   4.01   Transitional//EN "   "http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=UTF-8 ">
<title> Insert   title   here </title>
</head>
<body>
<a   href= "http://www.163.com "   target= "_parent "> www.163.com </a>
<button   onclick= "display() "> display   parent </button>
<script   type= "text/javascript "> <!--
function   display(){
var   parent   =   this.parent;
var   i   =   1;
while(parent     !=   null){
alert(i);
alert(parent);
i++;
if(   i   ==   10){
break;
}
parent   =   parent.parent;
}
}

                --> </script>
</body>
</html>


可是,为什么window.parent却永远不为null呢?奇怪!

------解决方案--------------------
顶层窗口引用的是本身