Internet Explorer 8 拒绝从弹出窗口下载文件
我正在制作一个网站。在一个地方有一个按钮执行 Ajax 回调,然后尝试通过 window.open()
下载文件。预期的行为是新窗口短暂闪烁,然后出现文件下载。这在 IE9 上工作正常,但 IE8 似乎有问题,即使禁用了弹出窗口阻止程序。
经过进一步的实验,我发现了另一个奇怪的行为。如果我在新打开的选项卡的地址栏中手动输入下载的 URL,则会收到一条错误消息。无法下载的一般情况。如果我现在尝试刷新页面(或者只需在地址栏中按 ENTER 键,从而重复相同的请求),下载就会顺利进行。
我预计它可能与 content-disposition
或 cache-control
标头有关,但删除这些标头并没有帮助。将 URL 添加到“可信站点”区域也没有。
无论如何,我将尝试用 window.location
重新制作它,因为我不喜欢弹出窗口(不是我制作的),但我对这种行为感到困惑。是什么原因造成的?
I'm crafting a website. In one place there is a button which performs an Ajax callback, and then tries to download a file via window.open()
. The expected behaviour is for the new window to flash briefly and then a file download to appear. This works fine on IE9, but IE8 seems to have a problem with that, even with popup blocker disabled.
After further experimenting I found another peculiar behavior. If I enter the URL of the download manually into the addressbar of a freshly opened tab, I get an error message. Something generic about not being able to download. If I now try to refresh the page (or just hit ENTER in the address bar, thereby repeating the same request), the download proceeds nicely.
I expected that it might have something to do with content-disposition
or cache-control
headers, but removing those didn't help. Nor did adding the URL to the "trusted sites" zone.
I'm going to try and remake it with window.location
instead anyway, because I don't like the popup (that wasn't made by me), but I'm puzzled about this behavior. What causes it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了类似的问题。事实证明,当您使用 AJAX 获取文件时,IE 无法打开文件。我使用的解决方案是不使用ajax。相反,我使用了一些 jQuery 和一个 iframe:
I ran across a similar issue. It turns out that IE has trouble opening files when you use AJAX to get them. The solution I used is to not use ajax. Instead I used a little jQuery and a
iframe
: