简体   繁体   English

window.open(URL)无法下载pdf文件

[英]window.open(url) fails to download the pdf file

I am trying to open a URL, which points to a PDF, using window.open(url). 我正在尝试使用window.open(url)打开一个指向PDF的URL。 In IE, the popup window flashes and nothing happens afterwords. 在IE中,弹出窗口闪烁,并且后言没有任何反应。 When I access the same url directly using IE, PDF opens up perfectly. 当我直接使用IE访问相同的URL时,PDF会完美打开。 In the HTML below, when I click on Link, I get the PDF but window.open fails. 在下面的HTML中,当我单击“链接”时,我得到了PDF,但window.open失败。 Moreover, if I provide a direct link of PDF in window.open that also works perfectly. 此外,如果我在window.open中提供PDF的直接链接,那么它也可以很好地工作。 Could any body shed some light on this? 有人能对此有所了解吗?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>

<BODY>
    <a href="http://phx.corporate-ir.net/External.File?item=UGFyZW50SUQ9NDk2Mjl8Q2hpbGRJRD0tMXxUeXBlPTM=&t=1">Link</a>
<script>
    url = "http://phx.corporate-ir.net/External.File?item=UGFyZW50SUQ9NDk2Mjl8Q2hpbGRJRD0tMXxUeXBlPTM=&t=1";        
    window.open(url);           
</script>
</BODY>
</HTML>

Thanks 谢谢

Most browsers block window.open when is called without user interaction in order to avoid popup advertisements. 大多数浏览器在没有用户交互的情况下阻止window.open when调用,以避免弹出广告。

Why are doing this anyway? 为什么要这样做? Instead you should link directly to the PDF in the original document, where you can use target="_blank" if it must be in a new window. 相反,您应该直接链接到原始文档中的PDF,如果它必须在新窗口中,则可以在其中使用target="_blank" (Keep in mind, that there are users that don't like it if websites open new windows). (请记住,如果网站打开新窗口,会有一些用户不喜欢它)。

这可能只是我的约定,但是我总是这样使用window.open()

var win = window.open(url);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM