简体   繁体   English

如何在IE 11的新标签页中自动打开下载的文件或Chrome中的边缘式文件下载功能

[英]How to auto open downloaded file in new tab in IE 11 or edge like file download work in chrome

I am using windows 10 . 我正在使用Windows 10。 I am using msSaveOrOpenBlob of javascript to download the blob return by the Ajax call in IE11. 我使用javascript的msSaveOrOpenBlob通过IE11中的Ajax调用下载blob返回。 There I don't need any prompt like open, save while downloaded. 在那里,我不需要任何提示,例如打开,下载时保存。 The PDF file should be opened in new tab exactly like it happen in chrome. PDF文件应在新标签页中打开,就像在chrome中一样。 But not happening. 但没有发生。

Then I checked with tag. 然后我检查了标签。 Then also it is not able to open without any prompt on click. 然后,如果没有任何点击提示,它将无法打开。

My code is like below. 我的代码如下。 click here to download 点击这里下载

File download option is enable and there is no option for prompt. 文件下载选项已启用,没有提示的选项。 PFB the prompt I am getting. PFB我得到的提示。 在此处输入图片说明

How a browser handles a PDF file depends on a combination of things. 浏览器如何处理PDF文件取决于多种因素。

1.) HTTP Headers 1.)HTTP标头

If you want the file to be treated as a file, vs. a "page" to load in the browser ensure you set the content-disposition to attachment and provide a filename with an extension ( with no spaces Firefox gets hung up on this) HTTP Content-Disposition Docs eg 如果要将文件视为文件,而不是在浏览器中加载“页面”,请确保将content-dispositionattachment并提供带extension filename extension (Firefox 不会在此挂断) HTTP内容处置文档,例如

Content-Disposition: attachment; filename="filename.pdf"

2.) New Tab/new window 2.)新标签页/新窗口

If you want your content to be loaded in another tab/window, you'll want to set the target attribute of your form/link to _blank . 如果希望将内容加载到另一个选项卡/窗口中,则需要将表单/链接的target属性设置为_blank

3.) Browser settings 3.)浏览器设置

If the browser has a plugin installed (eg Adobe Acrobat) to handle PDFs, there are configurations in Acrobat to determine if the app opens PDFs separately in the application... or "embedded" in the browser. 如果浏览器安装了用于处理PDF的插件(例如Adobe Acrobat),则Acrobat中有一些配置可以确定应用程序是在应用程序中单独打开PDF还是在浏览器中“嵌入”。 Note that modern browsers (Chrome/Firefox/etc.) also have their own built in PDF rendering without a need for a plugin. 请注意,现代浏览器(Chrome / Firefox / etc。)也有自己的内置PDF渲染功能,无需插件。

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

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