Sealyu

--- 博客已迁移至: http://www.sealyu.com/blog

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  618 随笔 :: 87 文章 :: 225 评论 :: 0 Trackbacks
最近做项目的时候碰到一个问题:
在js里面使用window.close(),IE下工作正常,但是FireFox下有时可以,有时不行。
搜索发现,可以这样解决:
<script   language="javascript"   type="text/javascript">  
   
  function   closeWindow()   {  
   
  window.open('','_parent','');  
   
  window.close();  
   
  }  
   
  </script>    
  <a   href="javascript:closeWindow();">Close   Window</a>
 
在前面加一句  window.open('','_parent','');  
作用为:
fool   the   browser   into   thinking   that   it   was   opened   with   a   script  
  This   opens   a   new   page,   (non-existent),   into   a   target   frame/window,   (_parent   which   of   course   is   the   window   in   which   the   script   is   executed,   so   replacing   itself),   and   defines   parameters   such   as   window   size   etc,   (in   this   case   none   are   defined   as   none   are   needed).   Now   that   the   browser   thinks   a   script   opened   a   page   we   can   quickly   close   it   in   the   standard   way…
posted on 2008-04-10 22:51 seal 阅读(6227) 评论(5)  编辑  收藏 所属分类: Javascript

评论

# re: FireFox 下 window.close()有时不能关闭 问题的解决 2008-04-11 17:10 Eric.Zhou
Good way!  回复  更多评论
  

# re: FireFox 下 window.close()有时不能关闭 问题的解决 2008-04-11 17:28 Eric.Zhou
有的firefox版本不支持上面的方法。
另:如果不需要弹出提示框,可以在window.close();上面加上:
window.opener=null;  回复  更多评论
  

# re: FireFox 下 window.close()有时不能关闭 问题的解决 2008-05-30 09:18 carol
这个办法在firefox里无效,要在about:conifg中设置dom启用脚本关闭才行  回复  更多评论
  

# re: FireFox 下 window.close()有时不能关闭 问题的解决[未登录] 2011-07-01 10:58 aaa
这方法恐怕不行吧,难道要访问的用户都去修改设置吗?  回复  更多评论
  

# re: FireFox 下 window.close()有时不能关闭 问题的解决 2011-07-01 10:59 seal
@aaa
这个行为是在代码里控制的,不用用户自行修改配置  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: