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

          主站蜘蛛池模板: 张家界市| 柳林县| 哈密市| 西峡县| 湖南省| 巢湖市| 巴中市| 平顺县| 巨野县| 若羌县| 龙游县| 蒲城县| 靖宇县| 宿松县| 五大连池市| 临夏县| 安阳市| 乐东| 镇江市| 武穴市| 平南县| 水富县| 延川县| 保靖县| 罗田县| 闵行区| 青铜峡市| 宜州市| 绥棱县| 八宿县| 辉县市| 绥德县| 枝江市| 林芝县| 蕉岭县| 河北区| 安达市| 宁陵县| 通山县| 井研县| 眉山市|