下载“ pdf”按钮在ipad / iphone上不起作用

时间:2019-05-20 09:30:39

标签: javascript iframe

我有以下JS代码,可让用户下载pdf文件。此代码有效,但在Ipad和Iphone上除外。

//s is the url to download
iso.downlURL = function(s)
{

  var iframe = document.getElementById("hiddenDownloader");
  if (iframe === null)
  {
    iframe = document.createElement('iframe');  
    iframe.id = "hiddenDownloader";
    iframe.style.visibility = 'hidden';
    document.body.appendChild(iframe);
  }
  iframe.src = s;

  return true;
};

我发现了以下帖子,可能有同样的问题:

File Download using iframe not working in Iphone/Ipad

但是我不确定他的建议是什么,如何更改?

-------------更新---------------------

我可能应该提到ipad和iphone的问题是下载按钮不可点击。它只是灰色/禁用

1 个答案:

答案 0 :(得分:0)

尝试在隐藏的iframe中显示PDF。在某些会被黑客下载的系统上。

它无法在iOS上使用,因为Mobile Safari没有任何“下载PDF”的概念。在Mobile Safari中下载PDF的唯一方法是:

  1. 在浏览器中正常打开
  2. 用户单击“共享此”按钮
  3. 用户选择一个应用程序(例如Good Reader),该应用程序会将PDF存储在其存储区域中

如果您想为不懂下载的浏览器提供可靠的“下载PDF”功能并具有合理的过渡位置,请使用the Content-Disposition header和常规链接。