【问题标题】:IE how to open new window to view pdf stream instead save and open fileIE如何打开新窗口查看pdf流而不是保存和打开文件
【发布时间】:2018-02-28 19:05:50
【问题描述】:

Java Web 应用程序: 我做了一些研究以查看从服务器检索到的 pdf 数据,即“应用程序/pdf”内容响应。
下面的 js 可以工作,但在 IE 中它打开/保存一个 pdf 文件,而不是打开一个新窗口来显示 pdf。
如何为IE打开一个新窗口?

var res = $http.post(printURL, dataset, {responseType: 'arraybuffer'});

res.success(function(response, status, headers, config) {

var file = new Blob([response], {type: 'application/pdf'});

if (window.navigator && window.navigator.msSaveOrOpenBlob) {
   window.navigator.msSaveOrOpenBlob(file);

}

else{
   var fileURL = URL.createObjectURL(file);
   window.open(fileURL);

}

【问题讨论】:

    标签: internet-explorer pdf blob


    【解决方案1】:

    尝试将以下内容添加到您的 .htaccess 文件中。

    Content-Type: application/pdf
    Content-Disposition: inline; filename="yourfile.pdf"
    

    请注意,您需要将 filename(在示例中为 yourfile.pdf)更改为您尝试在浏览器中强制打开的任何文件。

    【讨论】:

    • 谢谢!看起来不错的方法,我会尽快测试并及时更新。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-12
    • 2015-04-21
    相关资源
    最近更新 更多