Internet Explorer 8 拒绝从弹出窗口下载文件

发布于 2024-12-05 21:21:45 字数 483 浏览 0 评论 0原文

我正在制作一个网站。在一个地方有一个按钮执行 Ajax 回调,然后尝试通过 window.open() 下载文件。预期的行为是新窗口短暂闪烁,然后出现文件下载。这在 IE9 上工作正常,但 IE8 似乎有问题,即使禁用了弹出窗口阻止程序。

经过进一步的实验,我发现了另一个奇怪的行为。如果我在新打开的选项卡的地址栏中手动输入下载的 URL,则会收到一条错误消息。无法下载的一般情况。如果我现在尝试刷新页面(或者只需在地址栏中按 ENTER 键,从而重复相同的请求),下载就会顺利进行。

我预计它可能与 content-dispositioncache-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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

○闲身 2024-12-12 21:21:45

我遇到了类似的问题。事实证明,当您使用 AJAX 获取文件时,IE 无法打开文件。我使用的解决方案是不使用ajax。相反,我使用了一些 jQuery 和一个 iframe:

jquery - on click (dont need ajax/get)

            var dynamicUrl = 'SomeFileService.aspx?someQueryParam=' + input;
            $('#iframePopup').attr('src', dynamicUrl);
            window.frames["#iframePopup"].location.reload();

HTML

<iframe id="iframePopup" style="visibility:hidden;height:0px;width:0px;"></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:

jquery - on click (dont need ajax/get)

            var dynamicUrl = 'SomeFileService.aspx?someQueryParam=' + input;
            $('#iframePopup').attr('src', dynamicUrl);
            window.frames["#iframePopup"].location.reload();

HTML

<iframe id="iframePopup" style="visibility:hidden;height:0px;width:0px;"></iframe>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文