在新选项卡上的IE11中打开PDF而不提示 - mssaveoropenblob [英] Open PDF in IE11 on new tab without prompting - mssaveoropenblob

查看:1184
本文介绍了在新选项卡上的IE11中打开PDF而不提示 - mssaveoropenblob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在迁移ASP.NET MVC应用程序,该应用程序具有通过FileContentResult在新选项卡中打开PDF的功能。

We are migrating an ASP.NET MVC application, which had the feature to open PDF in a new tab via FileContentResult.

return new FileContentResult(byteArray, "application/pdf");

现在我们将此应用程序迁移到React,并从API(服务器端)迁移,我们正在发送返回响应如下: -

Now we are migrating this app to React and from from the API (server side), we are sending back the response as below :-

response.Content = new ByteArrayContent(pdfByteArray);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");

在React UI方面,我们使用如下响应: -

On the React UI side, we are using the response as below :-

postData(POST_API_ENDPOINT, requestData, ((err, data) => {
  if (data.ok) {
     data.blob().then(function(myBlob) {
         if (window.navigator && window.navigator.msSaveOrOpenBlob) {
            return window.navigator.msSaveOrOpenBlob(myBlob, "sample.pdf");
         }
         else {
           var objectURL = URL.createObjectURL(myBlob);
           return window.open(objectUrl);
          }
        });
      }
  }));

现在,据我所知,msSaveOrOpenBlob将始终提示用户在IE11中打开/保存。如果我需要在没有提示的情况下在不同的选项卡中打开PDF,我还有哪些其他选项?

Now, i understand that msSaveOrOpenBlob would always prompt the user to "open/save" within IE11. What other options do i have if i need to open the PDF in a different tab without the prompts?

我想通过以下方式有另一种方法可以做到这一点,但URL长度再次限制了。

I guess there is another way to do that via the below manner, but again the URL length limits that.

window.open("data:application/pdf;base64, " + base64EncodedPDF);


推荐答案

IE不允许我们在新版本中打开数据网址选项卡(可能是安全原因)并且没有解决方法 - 早先遇到同样的问题。

IE does not allow us to open Data URL in new tab (possibly security reason) and there no workaround - faced same issue earlier.

我们使用msSaveOrOpenBlob - 找不到替代方案。

We use msSaveOrOpenBlob - found no alternative.

这篇关于在新选项卡上的IE11中打开PDF而不提示 - mssaveoropenblob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆