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 閱讀(6271) 評論(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
          這個行為是在代碼里控制的,不用用戶自行修改配置  回復  更多評論
            

          主站蜘蛛池模板: 湄潭县| 灵台县| 象州县| 维西| 封开县| 斗六市| 博客| 龙口市| 楚雄市| 唐山市| 沾益县| 于田县| 定远县| 景德镇市| 尖扎县| 和平区| 祁连县| 城市| 博客| 伊金霍洛旗| 平顺县| 文水县| 高平市| 甘泉县| 东安县| 泌阳县| 广水市| 遂川县| 黔东| 荣昌县| 南城县| 科尔| 海南省| 永康市| 纳雍县| 手游| 保康县| 涿州市| 民县| 玛多县| 北辰区|