无法在Chrome IOS上加载PDF

[英]Trouble loading PDF on Chrome IOS


We're getting the following message from Chrome when downloading (or attempting to download) a pdf in our mobile web application.

在我们的移动网络应用程序中下载(或尝试下载)pdf时,我们会从Chrome收到以下消息。

"Warning: Something's not right here!... The site you are trying to access is acting strangely, and Chrome is unable to verify that the URL is correct."

“警告:有些东西不在这里!...您尝试访问的网站行为异常,Chrome无法验证网址是否正确。”

This is working fine in Safari and essentially we are doing this.

这在Safari中运行良好,基本上我们正在这样做。

  1. On load do a call to verify that the document that we want to show is OK.
    • if the document is not ok message the user and then close the tab
    • 如果文档不正确,则向用户发送消息,然后关闭选项卡
  2. 在加载时,请执行调用以验证我们要显示的文档是否正常。如果文档不正确,则向用户发送消息,然后关闭选项卡
  3. Direct the tab to navigate to an address which downloads the PDF.
  4. 指示选项卡以导航到下载PDF的地址。

Without posting too much code the Javascript is something like this:

没有发布太多代码,Javascript就是这样的:

DoRequest ("print_report",
           "VALIDATE",
           mycallback);

function mycallback (data,error) {

    var h_href = "";
    var h_widget = "";

    if(error == true) {
        window.close(); 
        return;
    }    

    h_href = GenerateHREF( "print_report", "PRINT" );

    window.location.href = h_href;        
}

The URL provided by GenerateHREF is for the same originating site and is relative to the original.
the mime type is set to application/pdf. The content-disposition is set to inline. I've tried setting the content-size header as well but it doesn't seem to have any effect.

GenerateHREF提供的URL适用于同一个原始站点,并且与原始站点相关。 mime类型设置为application / pdf。内容处置设置为内联。我也尝试过设置内容大小的标题,但似乎没有任何效果。

Content-Disposition: attachment; filename="pp66.26.pdf"
Content-Length: 31706
Content-Type: application/pdf

I'm missing something ... just what?

我错过了什么......什么?

3 个解决方案

#1


1  

Try to parse document to base64 and added to your document or iframe.

尝试将文档解析为base64并添加到您的文档或iframe中。

    function getAsyncBase64(fileName, callBack){
        var xhr = new XMLHttpRequest();
        xhr.open('GET', fileName, true);
        xhr.responseType = 'arraybuffer';
        xhr.onload = function (e) {
        if (this.status == 200) {
            var uInt8Array = new Uint8Array(this.response || this.responseText);
            var i = uInt8Array.length;
            var binaryString = new Array(i);
            while (i--) {
                binaryString[i] = String.fromCharCode(uInt8Array[i]);
            }
            var dataBinary = binaryString.join('');
            var data64 = window.btoa(dataBinary);
            callback(data64);                
        }
        xhr.send();
    };
    function callback(base64){
        window.open(base64, "_blank");
        //or
        iframe.src = "data:application/pdf;base64,"+ base64;
    };

    getAsyncBase64(url,callback);

#2


0  

If it's a popup/download issue you might be able to show it using an iframe?

如果是弹出/下载问题,您可以使用iframe显示它?

<iframe src="downloads/report.pdf"></iframe>

#3


0  

I also think that popup behavior is probably high on the list of suspects (specifically the window.close(); line seems pretty suspicious especially if the popup is blocked by the user).

我还认为弹出行为可能在嫌疑人列表中很高(特别是window.close();行似乎很可疑,特别是如果弹出窗口被用户阻止)。

However, since the ultimate goal is to download the file, you could try changing the response headers to

但是,由于最终目标是下载文件,因此您可以尝试将响应标头更改为

Content-Disposition: attachment; filename="pp66.26.pdf"
Content-Length: 31706
Content-Type: applicaton/octet-stream

or you could try forcing all pdfs in a particular folder to force a download via .htaccess file, then just linking to them via the location.href you are using:

或者您可以尝试强制特定文件夹中的所有pdf强制通过.htaccess文件下载,然后通过您正在使用的location.href链接到它们:

<FilesMatch "\.pdf$">
ForceType applicaton/octet-stream
Header set Content-Disposition attachment
</FilesMatch>

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2012/10/30/5665f9e68e340465ea40c3c52dd21b5c.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号