Sealyu

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

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            618 隨筆 :: 87 文章 :: 225 評論 :: 0 Trackbacks
          作者: sealyu   日期:2008-11-8

          今天在開發的時候,碰到客戶提到的一個問題,
          每次在下載文件的時候,IE都會阻止打開的保存文件的對話框。
          看了一下代碼,發現項目使用了一個stream servlet來處理文件下載,在使用ajax返回頁面后,使用window.open(link);打開保存對話框。
          問題應該就處在這里了,Google了一下,發現這是由于IE的安全機制。
          在微軟的網站上有這么一段話:

          Pop-Up Blocking

          The Pop-up Blocking feature blocks pop-up (and pop-under) windows initiated automatically by a Web site. Internet Explorer blocks Pop-up windows in the Internet and Restricted sites zones by default. However, the Pop-up Blocker enables pop-up windows initiated by a user action. Users can configure Internet Explorer 6 for Windows XP with SP2 to be more or less restrictive. Users can also turn off the Pop-up Blocker altogether. Generally, the Pop-up Blocker enables a window to open under the following circumstances:

          When initiated by user action, such as clicking a button or hyperlink

          When opened in the Trusted sites and Local intranet zones (considered safe)

          When opened by other applications running on the local computer

          The affected script methods are:

          window.open
          window.showHelp
          window.showModalDialog
          window.showModelessDialog
          window.external
          window.NavigateAndFind

          注:

          Pop-ups created with window.createPopup are unaffected by the Pop-up Blocker.

          在web編程過程中,經常會遇到一些頁面需要彈出窗口,但是在服務器端用window.open彈出的窗口會被IE阻止掉,showModalDialog彈出的窗口有時并不能滿足我們需要,我們需要彈出新的瀏覽器窗口。

           為什么我們編寫的彈出窗口會被IE阻止呢,原來IE會自動判斷彈出窗口的狀態,它會阻止自動彈出的窗口,而通過我們用鼠標點擊彈出的窗口,它是不會阻止的。這里就有一個問題,有人說:我的程序是寫在服務器按鈕里的,也是通過鼠標點擊彈出的呀!其實只有在加載頁面后,我們點擊到彈出這段時間頁面沒有被重新加載的情況下,彈出的窗口才不會被阻止!這也就是說,寫在服務器控件的回傳事件里的window.open都會被阻止。

          繼續Google解決辦法,在分析了幾種解決方法并進行對比之后,發現最簡單有效的方法如下:
          在window.open()函數中增加一個參數,將target設置為‘self’,
          即改為使用: window.open(link,'_self');
          問題解決。


          posted on 2008-11-08 17:16 seal 閱讀(10190) 評論(13)  編輯  收藏 所屬分類: Javascript

          評論

          # re: IE屏蔽window.open()窗口的解決辦法[未登錄] 2008-11-08 19:33 的的
          哦,不錯,學到了.thanks  回復  更多評論
            

          # re: IE屏蔽window.open()窗口的解決辦法 2008-11-09 08:51 ITGXG
          不錯  回復  更多評論
            

          # re: IE屏蔽window.open()窗口的解決辦法 2008-12-03 16:11 ss
          如果這樣做的話,他就等同于wondow.location.href的功能了!

            回復  更多評論
            

          # re: IE屏蔽window.open()窗口的解決辦法 2008-12-04 13:59 larkworm
          這不是等于更改原有窗口的URL ,根本還是沒有彈出窗口啊????  回復  更多評論
            

          # re: IE屏蔽window.open()窗口的解決辦法 2009-03-11 09:47 lhd
          如果這樣做的話,他就等同于wondow.location.href的功能了!

          就不能在新窗口打開了
            回復  更多評論
            

          # re: IE屏蔽window.open()窗口的解決辦法 2009-08-27 11:52 zl
          傳說中的簡單問題復雜化么。。。。  回復  更多評論
            

          # re: IE屏蔽window.open()窗口的解決辦法 2010-05-27 10:43 bigmonster
          老兄,不知道你有沒有去驗證。。。
          反正我試了是不行滴。。。  回復  更多評論
            

          # re: IE屏蔽window.open()窗口的解決辦法 2011-05-31 10:41 無語啊
          唉,要的要就彈出,你要是不彈出只改變本頁面的的話,那么解決的方法多的是了  回復  更多評論
            

          # re: IE屏蔽window.open()窗口的解決辦法[未登錄] 2011-11-23 16:59 無語
          你是不是在胡扯  回復  更多評論
            

          # re: IE屏蔽window.open()窗口的解決辦法[未登錄] 2012-07-23 15:57 test
          反正我試了是不行滴  回復  更多評論
            

          # re: IE屏蔽window.open()窗口的解決辦法 2012-08-30 18:15 jo
          胡扯  回復  更多評論
            

          # re: IE屏蔽window.open()窗口的解決辦法 2013-03-25 14:17 tet
          你試了嗎?根本就不能達到效果  回復  更多評論
            

          # re: IE屏蔽window.open()窗口的解決辦法 2014-11-17 15:10 123456
          反正我試了不行  回復  更多評論
            

          主站蜘蛛池模板: 晴隆县| 朝阳县| 横峰县| 天峻县| 榕江县| 太湖县| 福泉市| 嘉定区| 龙山县| 五寨县| 滨海县| 黑水县| 临泽县| 遂昌县| 钟祥市| 赤壁市| 威信县| 忻城县| 通许县| 安溪县| 洞头县| 天峻县| 绵竹市| 阳信县| 集贤县| 剑川县| 崇阳县| 福海县| 宁明县| 怀安县| 乳山市| 肃北| 光山县| 台中县| 富阳市| 县级市| 宝清县| 宜兴市| 珠海市| 阳春市| 彭山县|