iframe实现关闭当前窗口效果

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>b</title>
    <head>
     </head>
 <body>
      <div class="wrap" id="wrap" style="width:500px;height:500px;background:red;" > 
        点击隐藏
      </div> 
 <script type="text/javascript">
  document.getElementById("wrap").onclick=function(){
    window.parent.document.getElementById("main").style.display="none";
  }
 </script>
 </body>
 </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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>a</title>
<style type="text/css">
    #main{width:300px;height:200px;}
</style>
</head>
<body>
    <iframe id="main" src="test.htm"  frameborder="no" ></iframe>
</body>
</html>
打开a页面后,iframe即引入b页面,点击iframe中的div,iframe则会隐藏,以实现弹出的iframe关闭效果。
注意:必须在服务器上运行;
posted @ 2012-09-15 13:30  web小白  阅读(35818)  评论(2编辑  收藏  举报