Sealyu

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

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            618 隨筆 :: 87 文章 :: 225 評論 :: 0 Trackbacks
          最近做項(xiàng)目的時(shí)候碰到一個(gè)問題:
          在js里面使用window.close(),IE下工作正常,但是FireFox下有時(shí)可以,有時(shí)不行。
          搜索發(fā)現(xiàn),可以這樣解決:
          <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()有時(shí)不能關(guān)閉 問題的解決 2008-04-11 17:10 Eric.Zhou
          Good way!  回復(fù)  更多評論
            

          # re: FireFox 下 window.close()有時(shí)不能關(guān)閉 問題的解決 2008-04-11 17:28 Eric.Zhou
          有的firefox版本不支持上面的方法。
          另:如果不需要彈出提示框,可以在window.close();上面加上:
          window.opener=null;  回復(fù)  更多評論
            

          # re: FireFox 下 window.close()有時(shí)不能關(guān)閉 問題的解決 2008-05-30 09:18 carol
          這個(gè)辦法在firefox里無效,要在about:conifg中設(shè)置dom啟用腳本關(guān)閉才行  回復(fù)  更多評論
            

          # re: FireFox 下 window.close()有時(shí)不能關(guān)閉 問題的解決[未登錄] 2011-07-01 10:58 aaa
          這方法恐怕不行吧,難道要訪問的用戶都去修改設(shè)置嗎?  回復(fù)  更多評論
            

          # re: FireFox 下 window.close()有時(shí)不能關(guān)閉 問題的解決 2011-07-01 10:59 seal
          @aaa
          這個(gè)行為是在代碼里控制的,不用用戶自行修改配置  回復(fù)  更多評論
            

          主站蜘蛛池模板: 文安县| 盖州市| 微山县| 芮城县| 木兰县| 西畴县| 虹口区| 贺兰县| 长海县| 若尔盖县| 宁陵县| 宁夏| 师宗县| 佳木斯市| 宁都县| 若尔盖县| 宁南县| 定陶县| 乡城县| 且末县| 尉犁县| 宜宾县| 德江县| 铜陵市| 淮北市| 绿春县| 宁海县| 乌鲁木齐市| 江阴市| 临桂县| 普兰店市| 神池县| 连城县| 台湾省| 松江区| 岳池县| 施秉县| 芷江| 三门县| 淮阳县| 平武县|