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 阅读(10151) 评论(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
反正我试了不行  回复  更多评论
  


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


网站导航: